chore: refactored nvim config
f81b75e1
8 file(s) · +84 −109
| 1 | - | require("config.options") |
|
| 2 | - | require("config.keymaps") |
|
| 3 | - | require("config.autocmds") |
|
| 4 | - | require("core.plugins") |
|
| 5 | - | require("core.lsp") |
|
| 6 | - | require("core.treesitter") |
|
| 1 | + | require("options") |
|
| 2 | + | require("keymaps") |
|
| 3 | + | require("autocmds") |
|
| 4 | + | require("plugins") |
|
| 5 | + | require("lsp") |
|
| 6 | + | require("treesitter") |
| 56 | 56 | eob = " ", |
|
| 57 | 57 | } |
|
| 58 | 58 | vim.opt.shell = "sh" |
|
| 59 | - | ||
| 60 | - | if vim.fn.has("nvim-0.10") == 1 then |
|
| 61 | - | vim.opt.smoothscroll = true |
|
| 62 | - | end |
|
| 59 | + | vim.opt.smoothscroll = true |
|
| 63 | 60 | ||
| 64 | 61 | -- Treesitter folding |
|
| 65 | 62 | vim.o.foldenable = true |
| 1 | - | vim.lsp.enable({ |
|
| 2 | - | "astro", |
|
| 3 | - | "gopls", |
|
| 4 | - | "lua_ls", |
|
| 5 | - | "tsserver", |
|
| 6 | - | "rust-analyzer", |
|
| 7 | - | "solc", |
|
| 8 | - | "html", |
|
| 9 | - | "json" |
|
| 10 | - | }) |
|
| 11 | - | ||
| 12 | - | vim.api.nvim_create_autocmd("LspAttach", { |
|
| 13 | - | group = vim.api.nvim_create_augroup('lsp-attach', { clear = true }), |
|
| 14 | - | callback = function(event) |
|
| 15 | - | local map = function(keys, func, desc) |
|
| 16 | - | vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) |
|
| 17 | - | end |
|
| 18 | - | ||
| 19 | - | -- defaults: |
|
| 20 | - | -- https://neovim.io/doc/user/news-0.11.html#_defaults |
|
| 21 | - | ||
| 22 | - | map("gl", vim.diagnostic.open_float, "Open Diagnostic Float") |
|
| 23 | - | map("K", vim.lsp.buf.hover, "Hover Documentation") |
|
| 24 | - | map("gs", vim.lsp.buf.signature_help, "Signature Documentation") |
|
| 25 | - | map("gD", vim.lsp.buf.declaration, "Goto Declaration") |
|
| 26 | - | map("<leader>la", vim.lsp.buf.code_action, "Code Action") |
|
| 27 | - | map("<leader>lr", vim.lsp.buf.rename, "Rename all references") |
|
| 28 | - | map("<leader>lf", vim.lsp.buf.format, "Format") |
|
| 29 | - | map("<leader>v", "<cmd>vsplit | lua vim.lsp.buf.definition()<cr>", "Goto Definition in Vertical Split") |
|
| 30 | - | ||
| 31 | - | local function client_supports_method(client, method, bufnr) |
|
| 32 | - | if vim.fn.has 'nvim-0.11' == 1 then |
|
| 33 | - | return client:supports_method(method, bufnr) |
|
| 34 | - | else |
|
| 35 | - | return client.supports_method(method, { bufnr = bufnr }) |
|
| 36 | - | end |
|
| 37 | - | end |
|
| 38 | - | ||
| 39 | - | local client = vim.lsp.get_client_by_id(event.data.client_id) |
|
| 40 | - | if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then |
|
| 41 | - | local highlight_augroup = vim.api.nvim_create_augroup('lsp-highlight', { clear = false }) |
|
| 42 | - | ||
| 43 | - | -- When cursor stops moving: Highlights all instances of the symbol under the cursor |
|
| 44 | - | -- When cursor moves: Clears the highlighting |
|
| 45 | - | vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { |
|
| 46 | - | buffer = event.buf, |
|
| 47 | - | group = highlight_augroup, |
|
| 48 | - | callback = vim.lsp.buf.document_highlight, |
|
| 49 | - | }) |
|
| 50 | - | vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { |
|
| 51 | - | buffer = event.buf, |
|
| 52 | - | group = highlight_augroup, |
|
| 53 | - | callback = vim.lsp.buf.clear_references, |
|
| 54 | - | }) |
|
| 55 | - | ||
| 56 | - | -- When LSP detaches: Clears the highlighting |
|
| 57 | - | vim.api.nvim_create_autocmd('LspDetach', { |
|
| 58 | - | group = vim.api.nvim_create_augroup('lsp-detach', { clear = true }), |
|
| 59 | - | callback = function(event2) |
|
| 60 | - | vim.lsp.buf.clear_references() |
|
| 61 | - | vim.api.nvim_clear_autocmds { group = 'lsp-highlight', buffer = event2.buf } |
|
| 62 | - | end, |
|
| 63 | - | }) |
|
| 64 | - | end |
|
| 65 | - | end, |
|
| 66 | - | }) |
|
| 67 | - | ||
| 68 | - | vim.diagnostic.config({ |
|
| 69 | - | virtual_lines = false, |
|
| 70 | - | -- virtual_text = true, |
|
| 71 | - | underline = true, |
|
| 72 | - | update_in_insert = false, |
|
| 73 | - | severity_sort = true, |
|
| 74 | - | float = { |
|
| 75 | - | border = "rounded", |
|
| 76 | - | source = true, |
|
| 77 | - | }, |
|
| 78 | - | signs = { |
|
| 79 | - | text = { |
|
| 80 | - | [vim.diagnostic.severity.ERROR] = " ", |
|
| 81 | - | [vim.diagnostic.severity.WARN] = " ", |
|
| 82 | - | [vim.diagnostic.severity.INFO] = " ", |
|
| 83 | - | [vim.diagnostic.severity.HINT] = " ", |
|
| 84 | - | }, |
|
| 85 | - | numhl = { |
|
| 86 | - | [vim.diagnostic.severity.ERROR] = "ErrorMsg", |
|
| 87 | - | [vim.diagnostic.severity.WARN] = "WarningMsg", |
|
| 88 | - | }, |
|
| 89 | - | }, |
|
| 90 | - | }) |
| 1 | - | -- ============================================================================ |
|
| 2 | - | -- Colorscheme (must load at startup) |
|
| 3 | - | -- ============================================================================ |
|
| 1 | + | -- Colorscheme |
|
| 4 | 2 | vim.pack.add({ |
|
| 5 | 3 | "https://github.com/stevedylandev/darkmatter-nvim", |
|
| 6 | 4 | 'https://github.com/echasnovski/mini.nvim', |
|
| 7 | 5 | }) |
|
| 8 | 6 | vim.cmd.colorscheme('darkmatter') |
|
| 9 | 7 | ||
| 10 | - | -- ============================================================================ |
|
| 11 | 8 | -- Mini.nvim — startup modules |
|
| 12 | - | -- ============================================================================ |
|
| 13 | 9 | local win_config = function() |
|
| 14 | 10 | local height = math.floor(0.618 * vim.o.lines) |
|
| 15 | 11 | local width = math.floor(0.618 * vim.o.columns) |
|
| 63 | 59 | require('mini.statusline').setup() |
|
| 64 | 60 | require('mini.extra').setup() |
|
| 65 | 61 | ||
| 66 | - | -- ============================================================================ |
|
| 67 | 62 | -- Deferred — loads right after startup via vim.schedule() |
|
| 68 | - | -- ============================================================================ |
|
| 69 | 63 | vim.schedule(function() |
|
| 70 | 64 | vim.pack.add({ |
|
| 71 | 65 | "https://github.com/christoomey/vim-tmux-navigator", |
|
| 94 | 88 | }) |
|
| 95 | 89 | end) |
|
| 96 | 90 | ||
| 97 | - | -- ============================================================================ |
|
| 98 | 91 | -- Lazy — loads on InsertEnter |
|
| 99 | - | -- ============================================================================ |
|
| 100 | 92 | vim.api.nvim_create_autocmd('InsertEnter', { once = true, callback = function() |
|
| 101 | 93 | require("mini.completion").setup({ |
|
| 102 | 94 | mappings = { |
|
| 1 | + | vim.lsp.enable({ |
|
| 2 | + | "astro", |
|
| 3 | + | "gopls", |
|
| 4 | + | "lua_ls", |
|
| 5 | + | "tsserver", |
|
| 6 | + | "rust-analyzer", |
|
| 7 | + | "solc", |
|
| 8 | + | "html", |
|
| 9 | + | "json" |
|
| 10 | + | }) |
|
| 11 | + | ||
| 12 | + | vim.api.nvim_create_autocmd("LspAttach", { |
|
| 13 | + | group = vim.api.nvim_create_augroup('lsp-attach', { clear = true }), |
|
| 14 | + | callback = function(event) |
|
| 15 | + | local map = function(keys, func, desc) |
|
| 16 | + | vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) |
|
| 17 | + | end |
|
| 18 | + | ||
| 19 | + | map("gl", vim.diagnostic.open_float, "Open Diagnostic Float") |
|
| 20 | + | map("K", vim.lsp.buf.hover, "Hover Documentation") |
|
| 21 | + | map("gs", vim.lsp.buf.signature_help, "Signature Documentation") |
|
| 22 | + | map("gD", vim.lsp.buf.declaration, "Goto Declaration") |
|
| 23 | + | map("<leader>la", vim.lsp.buf.code_action, "Code Action") |
|
| 24 | + | map("<leader>lr", vim.lsp.buf.rename, "Rename all references") |
|
| 25 | + | map("<leader>lf", vim.lsp.buf.format, "Format") |
|
| 26 | + | map("<leader>v", "<cmd>vsplit | lua vim.lsp.buf.definition()<cr>", "Goto Definition in Vertical Split") |
|
| 27 | + | ||
| 28 | + | local highlight_augroup = vim.api.nvim_create_augroup('lsp-highlight', { clear = false }) |
|
| 29 | + | ||
| 30 | + | -- When cursor stops moving: Highlights all instances of the symbol under the cursor |
|
| 31 | + | vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { |
|
| 32 | + | buffer = event.buf, |
|
| 33 | + | group = highlight_augroup, |
|
| 34 | + | callback = vim.lsp.buf.document_highlight, |
|
| 35 | + | }) |
|
| 36 | + | ||
| 37 | + | -- When cursor moves: Clears the highlighting |
|
| 38 | + | vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { |
|
| 39 | + | buffer = event.buf, |
|
| 40 | + | group = highlight_augroup, |
|
| 41 | + | callback = vim.lsp.buf.clear_references, |
|
| 42 | + | }) |
|
| 43 | + | ||
| 44 | + | -- When LSP detaches: Clears the highlighting |
|
| 45 | + | vim.api.nvim_create_autocmd('LspDetach', { |
|
| 46 | + | group = vim.api.nvim_create_augroup('lsp-detach', { clear = true }), |
|
| 47 | + | callback = function(event2) |
|
| 48 | + | vim.lsp.buf.clear_references() |
|
| 49 | + | vim.api.nvim_clear_autocmds { group = 'lsp-highlight', buffer = event2.buf } |
|
| 50 | + | end, |
|
| 51 | + | }) |
|
| 52 | + | end, |
|
| 53 | + | }) |
|
| 54 | + | ||
| 55 | + | vim.diagnostic.config({ |
|
| 56 | + | virtual_lines = false, |
|
| 57 | + | underline = true, |
|
| 58 | + | update_in_insert = false, |
|
| 59 | + | severity_sort = true, |
|
| 60 | + | float = { |
|
| 61 | + | border = "rounded", |
|
| 62 | + | source = true, |
|
| 63 | + | }, |
|
| 64 | + | signs = { |
|
| 65 | + | text = { |
|
| 66 | + | [vim.diagnostic.severity.ERROR] = " ", |
|
| 67 | + | [vim.diagnostic.severity.WARN] = " ", |
|
| 68 | + | [vim.diagnostic.severity.INFO] = " ", |
|
| 69 | + | [vim.diagnostic.severity.HINT] = " ", |
|
| 70 | + | }, |
|
| 71 | + | numhl = { |
|
| 72 | + | [vim.diagnostic.severity.ERROR] = "ErrorMsg", |
|
| 73 | + | [vim.diagnostic.severity.WARN] = "WarningMsg", |
|
| 74 | + | }, |
|
| 75 | + | }, |
|
| 76 | + | }) |