From 2e3412c4106b0147ab6fc6b1d4d48a29c4820506 Mon Sep 17 00:00:00 2001 From: Felix Nehrke Date: Tue, 3 Feb 2026 00:28:49 +0100 Subject: [PATCH] Add descriptions for lsp-shortcuts Since I use which-key I can actually benefit a lot from meaningful descriptions of my custom shortcuts. Whenever I feel like I forgot a multi-key shortcut I can simply type the first letter (in my case usually "Space" or "g") and peek into the preview of whichkey. It lists all possible additional keystrokes and their descriptions, so this change makes it a lot easier for me to find the command I'm looking for. --- .config/nvim/lua/plugins/lsp.lua | 26 ++++++++++++++------------ .config/nvim/lua/plugins/vimwiki.lua | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua index 6bc4f60..ce6f4bc 100644 --- a/.config/nvim/lua/plugins/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -1,17 +1,19 @@ local on_attach = function(_, bufnr) + local desc = function (desc) + return { noremap = true, silent = true, buffer = bufnr, desc = desc } + end local ts = require("telescope.builtin") - local opts = { noremap = true, silent = true, buffer = bufnr } - vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) - vim.keymap.set("n", "ca", vim.lsp.buf.code_action, opts) - vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) - vim.keymap.set("n", "ge", vim.diagnostic.open_float, opts) - vim.keymap.set("n", "gf", function() vim.lsp.buf.format { async = true } end, opts) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) - vim.keymap.set("n", "gk", vim.lsp.buf.hover, opts) - vim.keymap.set("n", "gK", vim.lsp.buf.signature_help, opts) - vim.keymap.set("n", "gn", function() vim.diagnostic.jump({ count = 1, float = true }) end, opts) - vim.keymap.set("n", "gN", function() vim.diagnostic.jump({ count = -1, float = true }) end, opts) - vim.keymap.set("n", "gr", ts.lsp_references, opts) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, desc("Rename identifier")) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action, desc("Code actions")) + vim.keymap.set("n", "gd", vim.lsp.buf.definition, desc("Jump to definition")) + vim.keymap.set("n", "ge", vim.diagnostic.open_float, desc("Open diagnostics, show errors")) + vim.keymap.set("n", "gf", function() vim.lsp.buf.format { async = true } end, desc("Format code")) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, desc("Jump to implementation")) + vim.keymap.set("n", "gk", vim.lsp.buf.hover, desc("Show quick-docs")) + vim.keymap.set("n", "gK", vim.lsp.buf.signature_help, desc("Show signature")) + vim.keymap.set("n", "gn", function() vim.diagnostic.jump({ count = 1, float = true }) end, desc("Jump to next occurence")) + vim.keymap.set("n", "gN", function() vim.diagnostic.jump({ count = -1, float = true }) end, desc("Jump to previous occurence")) + vim.keymap.set("n", "gr", ts.lsp_references, desc("Search references")) vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") end diff --git a/.config/nvim/lua/plugins/vimwiki.lua b/.config/nvim/lua/plugins/vimwiki.lua index 65b58e0..6ad7cba 100644 --- a/.config/nvim/lua/plugins/vimwiki.lua +++ b/.config/nvim/lua/plugins/vimwiki.lua @@ -34,7 +34,7 @@ vim.api.nvim_create_autocmd("FileType", { vim.opt_local.wrap = true vim.opt_local.number = false vim.opt_local.relativenumber = false - vim.keymap.set("n", "ws", "Gw | G commit-and-push") + vim.keymap.set("n", "ws", "Gw | G commit-and-push", { desc = "Save, commit & push" }) end, })