formatting

This commit is contained in:
Kasper Juul Hermansen 2022-10-13 14:01:18 +02:00
parent 4399f2c45e
commit 2eb9117efa
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912

686
init.lua
View File

@ -6,381 +6,377 @@
-- where a value with no key simply has an implicit numeric key -- where a value with no key simply has an implicit numeric key
local config = { local config = {
-- Configure AstroNvim updates -- Configure AstroNvim updates
updater = { updater = {
remote = "origin", -- remote to use remote = "origin", -- remote to use
channel = "nightly", -- "stable" or "nightly" channel = "nightly", -- "stable" or "nightly"
version = "latest", -- "latest", tag name, or regex search like "v1.*" to only do updates before v2 (STABLE ONLY) version = "latest", -- "latest", tag name, or regex search like "v1.*" to only do updates before v2 (STABLE ONLY)
branch = "main", -- branch name (NIGHTLY ONLY) branch = "main", -- branch name (NIGHTLY ONLY)
commit = nil, -- commit hash (NIGHTLY ONLY) commit = nil, -- commit hash (NIGHTLY ONLY)
pin_plugins = nil, -- nil, true, false (nil will pin plugins on stable only) pin_plugins = nil, -- nil, true, false (nil will pin plugins on stable only)
skip_prompts = false, -- skip prompts about breaking changes skip_prompts = false, -- skip prompts about breaking changes
show_changelog = true, -- show the changelog after performing an update show_changelog = true, -- show the changelog after performing an update
auto_reload = false, -- automatically reload and sync packer after a successful update auto_reload = false, -- automatically reload and sync packer after a successful update
auto_quit = false, -- automatically quit the current session after a successful update auto_quit = false, -- automatically quit the current session after a successful update
-- remotes = { -- easily add new remotes to track -- remotes = { -- easily add new remotes to track
-- ["remote_name"] = "https://remote_url.come/repo.git", -- full remote url -- ["remote_name"] = "https://remote_url.come/repo.git", -- full remote url
-- ["remote2"] = "github_user/repo", -- GitHub user/repo shortcut, -- ["remote2"] = "github_user/repo", -- GitHub user/repo shortcut,
-- ["remote3"] = "github_user", -- GitHub user assume AstroNvim fork -- ["remote3"] = "github_user", -- GitHub user assume AstroNvim fork
-- }, -- },
}, },
-- Set colorscheme to use -- Set colorscheme to use
colorscheme = "tokyonight", colorscheme = "tokyonight",
-- Add highlight groups in any theme -- Add highlight groups in any theme
highlights = { highlights = {
-- init = { -- this table overrides highlights in all themes -- init = { -- this table overrides highlights in all themes
-- Normal = { bg = "#000000" }, -- Normal = { bg = "#000000" },
-- } -- }
-- duskfox = { -- a table of overrides/changes to the duskfox theme -- duskfox = { -- a table of overrides/changes to the duskfox theme
-- Normal = { bg = "#000000" }, -- Normal = { bg = "#000000" },
-- }, -- },
}, },
-- set vim options here (vim.<first_key>.<second_key> = value) -- set vim options here (vim.<first_key>.<second_key> = value)
options = { options = {
opt = { opt = {
-- set to true or false etc. -- set to true or false etc.
relativenumber = true, -- sets vim.opt.relativenumber relativenumber = true, -- sets vim.opt.relativenumber
number = true, -- sets vim.opt.number number = true, -- sets vim.opt.number
spell = false, -- sets vim.opt.spell spell = false, -- sets vim.opt.spell
signcolumn = "auto", -- sets vim.opt.signcolumn to auto signcolumn = "auto", -- sets vim.opt.signcolumn to auto
wrap = false, -- sets vim.opt.wrap wrap = false, -- sets vim.opt.wrap
}, },
g = { g = {
mapleader = " ", -- sets vim.g.mapleader mapleader = " ", -- sets vim.g.mapleader
cmp_enabled = true, -- enable completion at start cmp_enabled = true, -- enable completion at start
autopairs_enabled = true, -- enable autopairs at start autopairs_enabled = true, -- enable autopairs at start
diagnostics_enabled = true, -- enable diagnostics at start diagnostics_enabled = true, -- enable diagnostics at start
status_diagnostics_enabled = true, -- enable diagnostics in statusline status_diagnostics_enabled = true, -- enable diagnostics in statusline
}, },
}, },
-- If you need more control, you can use the function()...end notation -- If you need more control, you can use the function()...end notation
-- options = function(local_vim) -- options = function(local_vim)
-- local_vim.opt.relativenumber = true -- local_vim.opt.relativenumber = true
-- local_vim.g.mapleader = " " -- local_vim.g.mapleader = " "
-- local_vim.opt.whichwrap = vim.opt.whichwrap - { 'b', 's' } -- removing option from list -- local_vim.opt.whichwrap = vim.opt.whichwrap - { 'b', 's' } -- removing option from list
-- local_vim.opt.shortmess = vim.opt.shortmess + { I = true } -- add to option list -- local_vim.opt.shortmess = vim.opt.shortmess + { I = true } -- add to option list
-- --
-- return local_vim -- return local_vim
-- end, -- end,
-- Set dashboard header -- Set dashboard header
header = { header = {
" █████ ███████ ████████ ██████ ██████", " █████ ███████ ████████ ██████ ██████",
"██ ██ ██ ██ ██ ██ ██ ██", "██ ██ ██ ██ ██ ██ ██ ██",
"███████ ███████ ██ ██████ ██ ██", "███████ ███████ ██ ██████ ██ ██",
"██ ██ ██ ██ ██ ██ ██ ██", "██ ██ ██ ██ ██ ██ ██ ██",
"██ ██ ███████ ██ ██ ██ ██████", "██ ██ ███████ ██ ██ ██ ██████",
" ", " ",
" ███  ██ ██  ██ ██ ███  ███", " ███  ██ ██  ██ ██ ███  ███",
" ████  ██ ██  ██ ██ ████  ████", " ████  ██ ██  ██ ██ ████  ████",
" ██ ██  ██ ██  ██ ██ ██ ████ ██", " ██ ██  ██ ██  ██ ██ ██ ████ ██",
" ██  ██ ██  ██  ██  ██ ██  ██  ██", " ██  ██ ██  ██  ██  ██ ██  ██  ██",
" ██   ████   ████   ██ ██  ██", " ██   ████   ████   ██ ██  ██",
}, },
-- Default theme configuration -- Default theme configuration
default_theme = { default_theme = {
-- Modify the color palette for the default theme -- Modify the color palette for the default theme
colors = { colors = {
fg = "#abb2bf", fg = "#abb2bf",
bg = "#1e222a", bg = "#1e222a",
}, },
highlights = function(hl) -- or a function that returns a new table of colors to set highlights = function(hl) -- or a function that returns a new table of colors to set
local C = require("default_theme.colors") local C = require "default_theme.colors"
hl.Normal = { fg = C.fg, bg = C.bg } hl.Normal = { fg = C.fg, bg = C.bg }
-- New approach instead of diagnostic_style -- New approach instead of diagnostic_style
hl.DiagnosticError.italic = true hl.DiagnosticError.italic = true
hl.DiagnosticHint.italic = true hl.DiagnosticHint.italic = true
hl.DiagnosticInfo.italic = true hl.DiagnosticInfo.italic = true
hl.DiagnosticWarn.italic = true hl.DiagnosticWarn.italic = true
return hl return hl
end, end,
-- enable or disable highlighting for extra plugins -- enable or disable highlighting for extra plugins
plugins = { plugins = {
aerial = true, aerial = true,
beacon = false, beacon = false,
bufferline = true, bufferline = true,
dashboard = true, dashboard = true,
highlighturl = true, highlighturl = true,
hop = false, hop = false,
indent_blankline = true, indent_blankline = true,
lightspeed = false, lightspeed = false,
["neo-tree"] = true, ["neo-tree"] = true,
notify = true, notify = true,
["nvim-tree"] = false, ["nvim-tree"] = false,
["nvim-web-devicons"] = true, ["nvim-web-devicons"] = true,
rainbow = true, rainbow = true,
symbols_outline = false, symbols_outline = false,
telescope = true, telescope = true,
vimwiki = false, vimwiki = false,
["which-key"] = true, ["which-key"] = true,
}, },
}, },
-- Diagnostics configuration (for vim.diagnostics.config({...})) when diagnostics are on -- Diagnostics configuration (for vim.diagnostics.config({...})) when diagnostics are on
diagnostics = { diagnostics = {
virtual_text = true, virtual_text = true,
underline = true, underline = true,
}, },
-- Extend LSP configuration -- Extend LSP configuration
lsp = { lsp = {
-- enable servers that you already have installed without mason -- enable servers that you already have installed without mason
servers = { servers = {
-- "pyright" -- "pyright"
}, },
formatting = { formatting = {
format_on_save = true, -- enable or disable auto formatting on save format_on_save = true, -- enable or disable auto formatting on save
disabled = { -- disable formatting capabilities for the listed clients disabled = { -- disable formatting capabilities for the listed clients
-- "sumneko_lua", -- "sumneko_lua",
}, },
-- filter = function(client) -- fully override the default formatting function -- filter = function(client) -- fully override the default formatting function
-- return true -- return true
-- end -- end
}, },
-- easily add or disable built in mappings added during LSP attaching -- easily add or disable built in mappings added during LSP attaching
mappings = { mappings = {
n = { n = {
-- ["<leader>lf"] = false -- disable formatting keymap -- ["<leader>lf"] = false -- disable formatting keymap
}, },
}, },
-- add to the global LSP on_attach function -- add to the global LSP on_attach function
-- on_attach = function(client, bufnr) -- on_attach = function(client, bufnr)
-- end, -- end,
-- override the mason server-registration function -- override the mason server-registration function
-- server_registration = function(server, opts) -- server_registration = function(server, opts)
-- require("lspconfig")[server].setup(opts) -- require("lspconfig")[server].setup(opts)
-- end, -- end,
-- Add overrides for LSP server settings, the keys are the name of the server -- Add overrides for LSP server settings, the keys are the name of the server
["server-settings"] = { ["server-settings"] = {
-- example for addings schemas to yamlls -- example for addings schemas to yamlls
-- yamlls = { -- override table for require("lspconfig").yamlls.setup({...}) -- yamlls = { -- override table for require("lspconfig").yamlls.setup({...})
-- settings = { -- settings = {
-- yaml = { -- yaml = {
-- schemas = { -- schemas = {
-- ["http://json.schemastore.org/github-workflow"] = ".github/workflows/*.{yml,yaml}", -- ["http://json.schemastore.org/github-workflow"] = ".github/workflows/*.{yml,yaml}",
-- ["http://json.schemastore.org/github-action"] = ".github/action.{yml,yaml}", -- ["http://json.schemastore.org/github-action"] = ".github/action.{yml,yaml}",
-- ["http://json.schemastore.org/ansible-stable-2.9"] = "roles/tasks/*.{yml,yaml}", -- ["http://json.schemastore.org/ansible-stable-2.9"] = "roles/tasks/*.{yml,yaml}",
-- }, -- },
-- }, -- },
-- }, -- },
-- }, -- },
}, },
}, },
-- Mapping data with "desc" stored directly by vim.keymap.set(). -- Mapping data with "desc" stored directly by vim.keymap.set().
-- --
-- Please use this mappings table to set keyboard mapping since this is the -- Please use this mappings table to set keyboard mapping since this is the
-- lower level configuration and more robust one. (which-key will -- lower level configuration and more robust one. (which-key will
-- automatically pick-up stored data by this setting.) -- automatically pick-up stored data by this setting.)
mappings = { mappings = {
-- first key is the mode -- first key is the mode
n = { n = {
-- second key is the lefthand side of the map -- second key is the lefthand side of the map
-- mappings seen under group name "Buffer" -- mappings seen under group name "Buffer"
["<leader>bb"] = { "<cmd>tabnew<cr>", desc = "New tab" }, ["<leader>bb"] = { "<cmd>tabnew<cr>", desc = "New tab" },
["<leader>bc"] = { "<cmd>BufferLinePickClose<cr>", desc = "Pick to close" }, ["<leader>bc"] = { "<cmd>BufferLinePickClose<cr>", desc = "Pick to close" },
["<leader>bj"] = { "<cmd>BufferLinePick<cr>", desc = "Pick to jump" }, ["<leader>bj"] = { "<cmd>BufferLinePick<cr>", desc = "Pick to jump" },
["<leader>bt"] = { "<cmd>BufferLineSortByTabs<cr>", desc = "Sort by tabs" }, ["<leader>bt"] = { "<cmd>BufferLineSortByTabs<cr>", desc = "Sort by tabs" },
-- quick save -- quick save
-- ["<C-s>"] = { ":w!<cr>", desc = "Save File" }, -- change description but the same command -- ["<C-s>"] = { ":w!<cr>", desc = "Save File" }, -- change description but the same command
}, },
t = { t = {
-- setting a mapping to false will disable it -- setting a mapping to false will disable it
-- ["<esc>"] = false, -- ["<esc>"] = false,
}, },
}, },
-- Configure plugins -- Configure plugins
plugins = { plugins = {
init = { init = {
{ {
"nvim-telescope/telescope-file-browser.nvim", "nvim-telescope/telescope-file-browser.nvim",
after = "telescope.nvim", after = "telescope.nvim",
config = function() config = function() require("telescope").load_extension "file_browser" end,
require("telescope").load_extension("file_browser") },
end,
},
{ {
"ahmedkhalf/project.nvim", "ahmedkhalf/project.nvim",
after = "telescope.nvim", after = "telescope.nvim",
config = function() config = function()
require("project_nvim").setup({ require("project_nvim").setup {
-- Manual mode doesn't automatically change your root directory, so you have -- Manual mode doesn't automatically change your root directory, so you have
-- the option to manually do so using `:ProjectRoot` command. -- the option to manually do so using `:ProjectRoot` command.
manual_mode = false, manual_mode = false,
-- Methods of detecting the root directory. **"lsp"** uses the native neovim -- Methods of detecting the root directory. **"lsp"** uses the native neovim
-- lsp, while **"pattern"** uses vim-rooter like glob pattern matching. Here -- lsp, while **"pattern"** uses vim-rooter like glob pattern matching. Here
-- order matters: if one is not detected, the other is used as fallback. You -- order matters: if one is not detected, the other is used as fallback. You
-- can also delete or rearangne the detection methods. -- can also delete or rearangne the detection methods.
detection_methods = { "lsp", "pattern" }, detection_methods = { "lsp", "pattern" },
-- All the patterns used to detect root dir, when **"pattern"** is in -- All the patterns used to detect root dir, when **"pattern"** is in
-- detection_methods -- detection_methods
patterns = { ".git", "Makefile", "package.json" }, patterns = { ".git", "Makefile", "package.json" },
-- Table of lsp clients to ignore by name -- Table of lsp clients to ignore by name
-- eg: { "efm", ... } -- eg: { "efm", ... }
ignore_lsp = {}, ignore_lsp = {},
-- Don't calculate root dir on specific directories -- Don't calculate root dir on specific directories
-- Ex: { "~/.cargo/*", ... } -- Ex: { "~/.cargo/*", ... }
exclude_dirs = {}, exclude_dirs = {},
-- Show hidden files in telescope -- Show hidden files in telescope
show_hidden = false, show_hidden = false,
-- When set to false, you will get a message when project.nvim changes your -- When set to false, you will get a message when project.nvim changes your
-- directory. -- directory.
silent_chdir = true, silent_chdir = true,
-- What scope to change the directory, valid options are -- What scope to change the directory, valid options are
-- * global (default) -- * global (default)
-- * tab -- * tab
-- * win -- * win
scope_chdir = "global", scope_chdir = "global",
-- Path where project.nvim will store the project history for use in -- Path where project.nvim will store the project history for use in
-- telescope -- telescope
datapath = vim.fn.stdpath("data"), datapath = vim.fn.stdpath "data",
}) }
require("telescope").load_extension("projects") require("telescope").load_extension "projects"
end, end,
}, },
{ {
"pwntester/octo.nvim", "pwntester/octo.nvim",
after = "telescope.nvim", after = "telescope.nvim",
requires = { requires = {
"nvim-lua/plenary.nvim", "nvim-lua/plenary.nvim",
"nvim-telescope/telescope.nvim", "nvim-telescope/telescope.nvim",
"kyazdani42/nvim-web-devicons", "kyazdani42/nvim-web-devicons",
}, },
config = function() config = function() require("octo").setup() end,
require("octo").setup() },
end, -- You can disable default plugins as follows:
}, -- ["goolord/alpha-nvim"] = { disable = true },
-- You can disable default plugins as follows:
-- ["goolord/alpha-nvim"] = { disable = true },
-- You can also add new plugins here as well: -- You can also add new plugins here as well:
-- Add plugins, the packer syntax without the "use" -- Add plugins, the packer syntax without the "use"
-- { "andweeb/presence.nvim" }, -- { "andweeb/presence.nvim" },
-- { -- {
-- "ray-x/lsp_signature.nvim", -- "ray-x/lsp_signature.nvim",
-- event = "BufRead", -- event = "BufRead",
-- config = function() -- config = function()
-- require("lsp_signature").setup() -- require("lsp_signature").setup()
-- end, -- end,
-- }, -- },
-- We also support a key value style plugin definition similar to NvChad: -- We also support a key value style plugin definition similar to NvChad:
-- ["ray-x/lsp_signature.nvim"] = { -- ["ray-x/lsp_signature.nvim"] = {
-- event = "BufRead", -- event = "BufRead",
-- config = function() -- config = function()
-- require("lsp_signature").setup() -- require("lsp_signature").setup()
-- end, -- end,
-- }, -- },
}, },
-- All other entries override the require("<key>").setup({...}) call for default plugins -- All other entries override the require("<key>").setup({...}) call for default plugins
["null-ls"] = function(config) -- overrides `require("null-ls").setup(config)` ["null-ls"] = function(config) -- overrides `require("null-ls").setup(config)`
-- config variable is the default configuration table for the setup function call -- config variable is the default configuration table for the setup function call
local null_ls = require("null-ls") local null_ls = require "null-ls"
-- Check supported formatters and linters -- Check supported formatters and linters
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
config.sources = { config.sources = {
-- Set a formatter -- Set a formatter
null_ls.builtins.formatting.stylua, null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.prettier, null_ls.builtins.formatting.prettier,
null_ls.builtins.formatting.deno_fmt.with({ null_ls.builtins.formatting.deno_fmt.with {
filetypes = { "markdown" }, filetypes = { "markdown" },
}), },
} }
return config -- return final config table return config -- return final config table
end, end,
treesitter = { -- overrides `require("treesitter").setup(...)` treesitter = { -- overrides `require("treesitter").setup(...)`
ensure_installed = { "lua", "rust", "markdown", "typescript", "go" }, ensure_installed = { "lua", "rust", "markdown", "typescript", "go" },
}, },
-- use mason-lspconfig to configure LSP installations -- use mason-lspconfig to configure LSP installations
["mason-lspconfig"] = { -- overrides `require("mason-lspconfig").setup(...)` ["mason-lspconfig"] = { -- overrides `require("mason-lspconfig").setup(...)`
ensure_installed = { "sumneko_lua", "rust_analyzer", "gopls", "yamlls" }, ensure_installed = { "sumneko_lua", "rust_analyzer", "gopls", "yamlls" },
}, },
-- use mason-null-ls to configure Formatters/Linter installation for null-ls sources -- use mason-null-ls to configure Formatters/Linter installation for null-ls sources
["mason-null-ls"] = { -- overrides `require("mason-null-ls").setup(...)` ["mason-null-ls"] = { -- overrides `require("mason-null-ls").setup(...)`
-- ensure_installed = { "prettier", "stylua" }, -- ensure_installed = { "prettier", "stylua" },
}, },
}, },
-- LuaSnip Options -- LuaSnip Options
luasnip = { luasnip = {
-- Add paths for including more VS Code style snippets in luasnip -- Add paths for including more VS Code style snippets in luasnip
vscode_snippet_paths = {}, vscode_snippet_paths = {},
-- Extend filetypes -- Extend filetypes
filetype_extend = { filetype_extend = {
-- javascript = { "javascriptreact" }, -- javascript = { "javascriptreact" },
}, },
}, },
-- CMP Source Priorities -- CMP Source Priorities
-- modify here the priorities of default cmp sources -- modify here the priorities of default cmp sources
-- higher value == higher priority -- higher value == higher priority
-- The value can also be set to a boolean for disabling default sources: -- The value can also be set to a boolean for disabling default sources:
-- false == disabled -- false == disabled
-- true == 1000 -- true == 1000
cmp = { cmp = {
source_priority = { source_priority = {
nvim_lsp = 1000, nvim_lsp = 1000,
luasnip = 750, luasnip = 750,
buffer = 500, buffer = 500,
path = 250, path = 250,
}, },
}, },
-- Modify which-key registration (Use this with mappings table in the above.) -- Modify which-key registration (Use this with mappings table in the above.)
["which-key"] = { ["which-key"] = {
-- Add bindings which show up as group name -- Add bindings which show up as group name
register = { register = {
-- first key is the mode, n == normal mode -- first key is the mode, n == normal mode
n = { n = {
-- second key is the prefix, <leader> prefixes -- second key is the prefix, <leader> prefixes
["<leader>"] = { ["<leader>"] = {
-- third key is the key to bring up next level and its displayed -- third key is the key to bring up next level and its displayed
-- group name in which-key top level menu -- group name in which-key top level menu
["b"] = { name = "Buffer" }, ["b"] = { name = "Buffer" },
["P"] = { "<cmd>Telescope projects<cr>", "projects" }, ["P"] = { "<cmd>Telescope projects<cr>", "projects" },
}, },
}, },
}, },
}, },
-- This function is run last and is a good place to configuring -- This function is run last and is a good place to configuring
-- augroups/autocommands and custom filetypes also this just pure lua so -- augroups/autocommands and custom filetypes also this just pure lua so
-- anything that doesn't fit in the normal config locations above can go here -- anything that doesn't fit in the normal config locations above can go here
polish = function() polish = function()
-- Set up custom filetypes -- Set up custom filetypes
-- vim.filetype.add { -- vim.filetype.add {
-- extension = { -- extension = {
-- foo = "fooscript", -- foo = "fooscript",
-- }, -- },
-- filename = { -- filename = {
-- ["Foofile"] = "fooscript", -- ["Foofile"] = "fooscript",
-- }, -- },
-- pattern = { -- pattern = {
-- ["~/%.config/foo/.*"] = "fooscript", -- ["~/%.config/foo/.*"] = "fooscript",
-- }, -- },
-- } -- }
end, end,
} }
return config return config