diff --git a/.config/nvim/lua/keymap.lua b/.config/nvim/lua/keymap.lua index 71ad3a4..e38cd89 100644 --- a/.config/nvim/lua/keymap.lua +++ b/.config/nvim/lua/keymap.lua @@ -1,112 +1,115 @@ +-- highlighting yanked regions +local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) +vim.api.nvim_create_autocmd('TextYankPost', { + callback = function() + vim.highlight.on_yank() + end, + group = highlight_group, +}) + +local m = require 'mapx'.setup { global = true, whichkey = true } + -- unmap unwanted commands -vim.keymap.set({ 'n', 'v' }, '', '', { silent = true }) -vim.keymap.set({ 'n', 'i' }, '', '', { noremap = true }) -vim.keymap.set('i', '', '', { noremap = true }) -vim.keymap.set('i', '', '', { noremap = true }) -vim.keymap.set('i', '', '', { noremap = true }) -vim.keymap.set('i', '', '', { noremap = true }) -vim.keymap.set('i', '', '', { noremap = true }) -vim.keymap.set('i', '', '', { noremap = true }) -vim.keymap.set({ 'n', 'i' }, '', '', { noremap = true }) -vim.keymap.set({ 'n', 'i' }, '', '', { noremap = true }) -vim.keymap.set({ 'n', 'i' }, '', '', { noremap = true }) -vim.keymap.set({ 'n', 'i' }, '', '', { noremap = true }) +m.nnoremap("", '') +m.inoremap("", '') +m.nnoremap("", '') +m.inoremap("", '') +m.inoremap("", '') +m.inoremap("", '') +m.inoremap("", '') +m.inoremap("", '') +m.inoremap("", '') +m.inoremap("", '') +m.nnoremap("", '') +m.inoremap("", '') +m.nnoremap("", '') +m.inoremap("", '') +m.nnoremap("", '') +m.inoremap("", '') +m.nnoremap("", '') +m.nnoremap("ZT", '') +m.nnoremap("Zt", '') -- shortcut for split navigation -vim.keymap.set('n', '', 'h', { noremap = true }) -vim.keymap.set('n', '', 'j', { noremap = true }) -vim.keymap.set('n', '', 'k', { noremap = true }) -vim.keymap.set('n', '', 'l', { noremap = true }) +m.nnoremap("", 'h', 'splits: go to left split') +m.nnoremap("", 'j', 'splits: go to lower split') +m.nnoremap("", 'k', 'splits: go to upper split') +m.nnoremap("", 'l', 'splits: go to right split') -- compiler for languages -vim.keymap.set('n', 'c', ':w! | !compiler %', { noremap = true }) +m.nnoremap("c", ':w! | !compiler %', 'Compile current file') -- save file as sudo on files that require root permission -vim.keymap.set('c', 'w!!', 'execute "silent! write !sudo tee % >/dev/null" edit!', { noremap = true }) +m.cname("w", "Write") +m.cname("w!", "Write with sudo") +m.cnoremap("w!!", 'execute "silent! write !sudo tee % >/dev/null" edit!', 'Write file over with sudo') -- easy substitution for whole file and line, visual mode -vim.keymap.set('n', 'ss', ':%s/\\<\\>//g', { noremap = true }) -vim.keymap.set({ 'n', 'v' }, 'sl', ':s//g', { noremap = true }) -vim.keymap.set('n', 'sa', ':%s//g', { noremap = true }) - --- highlighting yanked regions -local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) -vim.api.nvim_create_autocmd('TextYankPost', { - callback = function() - vim.highlight.on_yank() - end, - group = highlight_group, -}) +m.nname("s", "Substitute") +m.nnoremap("ss", ':%s/\\<\\>//g', 'Substitute: word under cursor') +m.nnoremap("sa", ':%s//g', 'Substitute: free form') -- remap for dealing with word wrap -vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", - { - expr = true, - silent = true - }) - -vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", - { - expr = true, - silent = true - }) +m.nmap('k', "v:count == 0 ? 'gk' : 'k'", { "expr", "silent" }, 'go up in wrapped lines') + +m.nmap('j', "v:count == 0 ? 'gj' : 'j'", { "expr", "silent" }, 'go down in wrapped lines') -- stevearc/aerial.nvim -vim.keymap.set('n', '', ':AerialToggle!', {}) +m.nmap('', ':AerialToggle!', 'Aerial: Open side window') -- nvim-tree/nvim-tree.lua -vim.keymap.set('n', '', ':NvimTreeToggle toggle', {}) +m.nmap("", ':NvimTreeToggle toggle', 'NvimTree: toggle') -- numtostr/fterm.nvim -vim.keymap.set({ 'n', 't' }, 't', require("FTerm").toggle, { noremap = true }) +m.nname("t", "FTerm") +m.nnoremap("tt", require("FTerm").toggle, 'Terminal: toggle') +m.tnoremap("tt", require("FTerm").toggle, 'Terminal: toggle') + + +-- sindrets/diffview.nvim +m.nname("g", "Git") local lazygit = require("FTerm"):new({ cmd = 'lazygit', }) -vim.keymap.set({ 'n', 't' }, 'gt', function() lazygit:toggle() end) +m.nnoremap("tg", function() lazygit:toggle() end, 'Lazygit: toggle') +m.tnoremap("tg", function() lazygit:toggle() end, 'Lazygit: toggle') --- sindrets/diffview.nvim -vim.keymap.set('n', 'gdo', ":DiffviewOpen") -vim.keymap.set('n', 'gdc', ":DiffviewClose") +m.nname("gd", "Git Diff") +m.nmap("gdo", ":DiffviewOpen", "Git Diff: open") +m.nmap("gdc", ":DiffviewClose", "Git Diff: close") -- folke/trouble.nvim -vim.keymap.set('n', 'x', ":TroubleToggle") +m.nmap("x", ":TroubleToggle", "Trouble: toggle") -- hrsh7th/nvim-cmp -vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, { noremap = true }) -vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { noremap = true }) -vim.keymap.set('n', 'gy', vim.lsp.buf.type_definition, { noremap = true }) -vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { noremap = true }) -vim.keymap.set('n', 'gr', vim.lsp.buf.references, { noremap = true }) -vim.keymap.set('n', 'K', vim.lsp.buf.hover, { noremap = true }) -vim.keymap.set('n', '', function() - require("conform").format({ async = true, lsp_fallback = true }) -end, { noremap = true }) +m.nname("g", "LSP: goto") +m.nnoremap("gD", vim.lsp.buf.declaration, "LSP: goto declaration") +m.nnoremap("gd", vim.lsp.buf.definition, "LSP: goto definition") +m.nnoremap("gy", vim.lsp.buf.type_definition, "LSP: goto type definition") +m.nnoremap("gi", vim.lsp.buf.implementation, "LSP: list implementation") +m.nnoremap("gr", vim.lsp.buf.references, "LSP: list references") +m.nnoremap("K", vim.lsp.buf.hover, "LSP: show documentation") +m.nnoremap("", function() require("conform").format({ async = true, lsp_fallback = true }) end, "LSP: format") -- filipdutescu/renamer.nvim -vim.keymap.set('n', '', require("renamer").rename, { noremap = true }) +m.nnoremap("", require("renamer").rename, "LSP: rename") -- nvim-telescope/telescope.nvim -vim.keymap.set('n', '', ':Telescope find_files', { noremap = true }) +m.nnoremap("", ':Telescope find_files', "Telescope: find files") -- kamykn/spelunker.vim -vim.keymap.set('n', '', ':call spelunker#toggle()', { noremap = true }) -vim.keymap.set('n', 'ZT', '', { noremap = true }) -vim.keymap.set('n', 'Zt', '', { noremap = true }) +m.nnoremap("", ':call spelunker#toggle()', "Spelunker: toggle") -- kevinhwang91/nvim-ufo -vim.keymap.set('n', 'K', function() +m.nnoremap("K", function() local winid = require('ufo').peekFoldedLinesUnderCursor() if not winid then vim.lsp.buf.hover() end -end) +end, "UFO: peek folded section") -- kevinhwang91/nvim-hlslens -local kopts = {noremap = true, silent = true} - -vim.api.nvim_set_keymap('n', 'n', - [[execute('normal! ' . v:count1 . 'n')lua require('hlslens').start()]], - kopts) -vim.api.nvim_set_keymap('n', 'N', - [[execute('normal! ' . v:count1 . 'N')lua require('hlslens').start()]], - kopts) +m.nnoremap("n", [[execute('normal! ' . v:count1 . 'n')lua require('hlslens').start()]], + 'silent', "HLSens: search forward") +m.nnoremap("N", [[execute('normal! ' . v:count1 . 'N')lua require('hlslens').start()]], + 'silent', "HLSens: search backwards") diff --git a/.config/nvim/lua/plugins/mapx.lua b/.config/nvim/lua/plugins/mapx.lua new file mode 100644 index 0000000..6ebc2c9 --- /dev/null +++ b/.config/nvim/lua/plugins/mapx.lua @@ -0,0 +1,9 @@ +return { + -- improved keybindings, previewing them + { + "b0o/mapx.nvim", + dependencies = { + "folke/which-key.nvim", + } + } + }