[neovim] Add descriptions to keymaps

This commit is contained in:
Adam Cooper 2023-11-15 08:53:13 -05:00
parent e5b0b7256e
commit c1e9169c7f
2 changed files with 40 additions and 37 deletions

View file

@ -1,6 +1,6 @@
HOME = os.getenv("HOME") HOME = os.getenv("HOME")
-- Configure the clipboard to access the \"+ and \"* registers -- Configure the clipboard to access the "+ and "* registers
-- (not sure why I need this now and didn't before) -- (not sure why I need this now and didn't before)
vim.opt.clipboard = "unnamedplus,unnamed" vim.opt.clipboard = "unnamedplus,unnamed"
@ -116,10 +116,10 @@ require('lualine').setup {
} }
local builtin = require('telescope.builtin') local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {}) vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = 'Telescope: find files' })
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {}) vim.keymap.set('n', '<leader>fg', builtin.live_grep, { desc = 'Telescope: live grep' })
vim.keymap.set('n', '<leader>fb', builtin.buffers, {}) vim.keymap.set('n', '<leader>fb', builtin.buffers, { desc = 'Telescope: buffers' })
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {}) vim.keymap.set('n', '<leader>fh', builtin.help_tags, { desc = 'Telescope: help tags' })
-------------------- --------------------
-- nvim-lspconfig -- -- nvim-lspconfig --
@ -167,10 +167,10 @@ lspconfig.rust_analyzer.setup {
-- Global mappings. -- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions -- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float) vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, { desc = 'Diagnostic: open float' })
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Diagnostic: go to previous' })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Diagnostic: go to next' })
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist) vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, { desc = 'Diagnostic: set loclist' })
-- Use LspAttach autocommand to only map the following keys -- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer -- after the language server attaches to the current buffer
@ -182,27 +182,29 @@ vim.api.nvim_create_autocmd('LspAttach', {
-- Buffer local mappings. -- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions -- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf } local opts = function(desc)
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) return { buffer = ev.buf, desc = desc }
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) end
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts('LSP: go to declaration'))
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts('LSP: go to definition'))
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts('LSP: hover'))
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts('LSP: go to implementation'))
-- This setting steps on my split navigation setting, so I changed it -- This setting steps on my split navigation setting, so I changed it
-- to the probably harmless F9. -- to the probably harmless F9.
-- vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts) -- vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts(''))
vim.keymap.set('n', '<F9>', vim.lsp.buf.signature_help, opts) vim.keymap.set('n', '<F9>', vim.lsp.buf.signature_help, opts('LSP: signature help'))
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts) vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts('LSP: add workspace folder'))
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts) vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts('LSP: remove workspace folder'))
vim.keymap.set('n', '<space>wl', function() vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts) end, opts('LSP: list workspace folder'))
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts) vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts('LSP: go to type definition'))
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts) vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts('LSP: rename token'))
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts) vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts('LSP: code action'))
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts('LSP: go to references'))
vim.keymap.set('n', '<space>f', function() vim.keymap.set('n', '<space>f', function()
vim.lsp.buf.format { async = true } vim.lsp.buf.format { async = true }
end, opts) end, opts('LSP: format'))
end, end,
}) })
@ -331,19 +333,19 @@ require('gitsigns').setup({
end, {expr=true}) end, {expr=true})
-- Actions -- Actions
map('n', '<leader>hs', gs.stage_hunk) map('n', '<leader>hs', gs.stage_hunk, { desc = 'GitSigns: stage hunk' })
map('n', '<leader>hr', gs.reset_hunk) map('n', '<leader>hr', gs.reset_hunk, { desc = 'GitSigns: reset hunk' })
map('v', '<leader>hs', function() gs.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end) map('v', '<leader>hs', function() gs.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end, { desc = 'GitSigns: stage hunk' })
map('v', '<leader>hr', function() gs.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end) map('v', '<leader>hr', function() gs.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end, { desc = 'GitSigns: reset hunk' })
map('n', '<leader>hS', gs.stage_buffer) map('n', '<leader>hS', gs.stage_buffer, { desc = 'GitSigns: stage buffer' })
map('n', '<leader>hu', gs.undo_stage_hunk) map('n', '<leader>hu', gs.undo_stage_hunk, { desc = 'GitSigns: undo stage hunk' })
map('n', '<leader>hR', gs.reset_buffer) map('n', '<leader>hR', gs.reset_buffer, { desc = 'GitSigns: reset_buffer' })
map('n', '<leader>hp', gs.preview_hunk) map('n', '<leader>hp', gs.preview_hunk, { desc = 'GitSigns: preview hunk' })
map('n', '<leader>hb', function() gs.blame_line{full=true} end) map('n', '<leader>hb', function() gs.blame_line{full=true} end, { desc = 'GitSigns: blame line' })
map('n', '<leader>tb', gs.toggle_current_line_blame) map('n', '<leader>tb', gs.toggle_current_line_blame, { desc = 'GitSigns: toggle current line blame' })
map('n', '<leader>hd', gs.diffthis) map('n', '<leader>hd', gs.diffthis, { desc = 'GitSigns: diff this' })
map('n', '<leader>hD', function() gs.diffthis('~') end) map('n', '<leader>hD', function() gs.diffthis('~') end, { desc = 'GitSigns: diff this' })
map('n', '<leader>td', gs.toggle_deleted) map('n', '<leader>td', gs.toggle_deleted, { desc = 'GitSigns: toggle deleted' })
end end
}) })

View file

@ -9,3 +9,4 @@ Ukraine
leak leak
leak leak
wolff wolff
baffler