Last active
September 19, 2025 12:37
-
-
Save alexsaezm/5774ed68d0cb53bb46355a82d6a35f18 to your computer and use it in GitHub Desktop.
Minimal NeoVim (>=0.11) configuration with LSP support without plugins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Set space as the leader key. Needs to happen first thing. | |
| vim.g.mapleader = " " | |
| vim.g.maplocalleader = " " | |
| -- Gutter settings | |
| vim.opt.number = true | |
| vim.opt.relativenumber = true | |
| vim.opt.signcolumn = "yes" | |
| -- Colorscheme & style | |
| vim.cmd.colorscheme("unokai") | |
| vim.api.nvim_set_hl(0, "Normal", { bg = "none" }) | |
| vim.api.nvim_set_hl(0, "NormalNC", { bg = "none" }) | |
| vim.api.nvim_set_hl(0, "EndOfBuffer", { bg = "none" }) | |
| -- Navigation | |
| vim.opt.scrolloff = 10 | |
| vim.opt.sidescrolloff = 8 | |
| vim.keymap.set('n', '<leader>e', ':Explore<CR>') | |
| -- Copy & Paste & History | |
| vim.opt.clipboard:append("unnamedplus") | |
| vim.opt.backup = false | |
| vim.opt.writebackup = false | |
| vim.opt.swapfile = false | |
| vim.opt.undofile = true | |
| vim.opt.updatetime = 300 | |
| vim.opt.timeoutlen = 500 | |
| vim.opt.ttimeoutlen = 0 | |
| vim.opt.autoread = true | |
| vim.opt.autowrite = false | |
| -- Create undo directory if it doesn't exist | |
| vim.opt.undodir = vim.fn.expand("~/.vim/undodir") | |
| local undodir = vim.fn.expand("~/.vim/undodir") | |
| if vim.fn.isdirectory(undodir) == 0 then | |
| vim.fn.mkdir(undodir, "p") | |
| end | |
| -- LSP support | |
| vim.lsp.config["gopls"] = { | |
| cmd = {"gopls"}, | |
| filetypes = { "go" }, | |
| } | |
| vim.lsp.enable("gopls") | |
| -- Attach to a buffer | |
| vim.api.nvim_create_autocmd("LspAttach", { | |
| callback = function(ev) | |
| local client = vim.lsp.get_client_by_id(ev.data.client_id) | |
| if client:supports_method("textDocument/completion") then | |
| vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true }) | |
| end | |
| local opts = { buffer = ev.buf } | |
| -- Open quickfix vertically | |
| local function open_in_qf(options) | |
| vim.fn.setqflist({}, ' ', options) | |
| vim.cmd("copen | wincmd H") | |
| end | |
| -- Navigation | |
| vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) | |
| vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) | |
| vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) | |
| vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) | |
| vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, opts) | |
| -- Symbols | |
| vim.keymap.set("n", "ds", function() | |
| vim.lsp.buf.document_symbol({ on_list = open_in_qf }) | |
| end, opts) | |
| vim.keymap.set("n", "<leader>ws", function() | |
| vim.lsp.buf.workspace_symbol(nil, { on_list = open_in_qf }) | |
| end, opts) | |
| -- Documentation | |
| vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) | |
| vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts) | |
| vim.keymap.set("i", "<C-k>", vim.lsp.buf.signature_help, opts) | |
| vim.keymap.set("n", "<leader>ld", vim.diagnostic.setloclist, opts) | |
| -- Code actions | |
| vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts) | |
| vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) | |
| vim.keymap.set("n", "<leader>f", vim.lsp.buf.format, opts) | |
| -- Use CTRL-space to trigger LSP completion. | |
| -- Use CTRL-Y to select an item. |complete_CTRL-Y| | |
| vim.keymap.set("i", "<c-space>", function() | |
| vim.lsp.completion.get() | |
| end) | |
| end, | |
| }) | |
| -- Avoid selecting the first item in the list | |
| vim.cmd("set completeopt+=noselect") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment