--[[ Keymappings for nvim experience. I use combination of both nvim default vim.api.nvim_set_keymap and WhichKey register. Slowly migrating to the WhichKey system, and tweaking the groupings as I go. --]] local key = vim.api.nvim_set_keymap local remap = { noremap = true, silent = true } local wk = require("which-key") -- ╭──────────────────────────────────────────────────────────╮ -- │ Register keybindings │ -- ╰──────────────────────────────────────────────────────────╯ -- Register in all modes, prefix wk.register({ b = { name = "Buffer", n = { "tabnew", "New tab", }, c = { name = "Comments", b = { "lua require('comment-box').lbox()", "Left aligned fixed size box with left aligned text", }, c = { "lua require('comment-box').ccbox()", desc = "Centered adapted box with centered text", }, l = { "lua require('comment-box').cline()", desc = "Centered line", }, }, d = { name = "Delete buffers", h = { "lua require('close_buffers').delete({type = 'hidden'})", "Delete hidden buffers", }, }, }, D = { name = "[D]iagnostics (Trouble)", t = { ":TroubleToggle", "[D]iagnostics [t]oggle" }, -- Quick navigation between diagonostics. f = { ":lua vim.diagnostic.open_float()", "[D]iagnostics: Open [f]loat" }, n = { ":lua vim.diagnostic.goto_next()", "[D]iagnostics: [n]ext" }, p = { ":lua vim.diagnostic.goto_prev()", "[D]iagnostics: [p]rev" }, }, f = { name = "[f]ind", -- Find recursively files across the root folder subfiles. f = { ':lua require("telescope.builtin").find_files()', "[f]ind [f]iles" }, -- Find recursively a text across the root folder subfiles. g = { ':lua require("telescope.builtin").live_grep()', "[f]ind text with [g]rep" }, }, h = { name = "[h]arpoon", a = { "lua require('harpoon.mark').add_file()", "[h]arpoon: [A]dd file" }, r = { "lua require('harpoon.mark').rm_file()", "[h]arpoon: [r]emove file" }, m = { "lua require('harpoon.ui').toggle_quick_menu()", "[h]arpoon: harpoon [m]enu" }, n = { "lua require('harpoon.ui').nav_next()", "[h]arpoon: [n]ext file" }, p = { "lua require('harpoon.ui').nav_prev()", "[h]arpoon: [p]revious file" }, ["1"] = { " lua require('harpoon.ui').nav_file(1)", "[h]arpoon: file 1" }, ["2"] = { " lua require('harpoon.ui').nav_file(2)", "[h]arpoon: file 2" }, ["3"] = { " lua require('harpoon.ui').nav_file(3)", "[h]arpoon: file 3" }, }, --- Remap debugging to "H" from LV default of "h" H = { name = "[H]elp/Conceal/Telescope", c = { name = "[c]onceal", h = { ":set conceallevel=1", "hide/conceal" }, s = { ":set conceallevel=0", "show/unconceal" }, }, t = { name = "Treesitter", t = { vim.treesitter.inspect_tree, "show tree" }, c = { ":=vim.treesitter.get_captures_at_cursor()", "show capture" }, n = { ":=vim.treesitter.get_node():type()", "show node" }, }, }, p = { name = "[p]lugins", i = { function() require("lazy").install() end, "[p]lugins [i]nstall" }, s = { function() require("lazy").home() end, "[p]lugins [s]tatus" }, S = { function() require("lazy").sync() end, "[p]lugins [S]ync" }, u = { function() require("lazy").check() end, "[p]lugins Check [u]pdates" }, U = { function() require("lazy").update() end, "[p]lugins [U]pdate" }, }, q = { name = "[q]uit", q = { ":qa", "[q]uit: [q]uit all" }, f = { ":qa!", "[q]uit: all with [f]orce" }, }, t = { name = "[t]elescope", -- Find recursively TODOs, NOTEs, FIXITs, ... across the root folder subfiles. t = { ":TodoTelescope", "[t]elescope: [t]odo" }, }, x = { ":Bdelete", "[x]: Close current buffer" }, }, { prefix = "" }) -- Normal mode, prefix wk.register({ b = { name = "Buffer" }, }, { mode = "n", prefix = "" }) -- Insert mode, prefix wk.register({ b = { name = "Buffer" }, }, { mode = "i", prefix = "" }) -- Go to the next block. --key('n', '', 'g%', remap ) -- Loop through brackets blocks. --key('n', '', 'z%', remap ) -- Do just End on CTRL + End. key("i", "", "", remap) key("n", "", "", remap) -- Do just Home on CTRL + Home. key("i", "", "", remap) -- Highlight the word after pressing enter. key( "n", "", [[:let searchTerm = '\v<'.expand("").'>' let @/ = searchTerm echo '/'.@/ call histadd("search", searchTerm) set hls]], remap ) -- Highlight the visual selection after pressing enter. key( "v", "", [["*y:silent! let searchTerm = '\V'.substitute(escape(@*, '\/'), "\n", '\\n', "g") let @/ = searchTerm echo '/'.@/ call histadd("search", searchTerm) set hls]], remap ) -- Toggle highlight of search key("n", "", ":set hlsearch!", remap) -- Toggle the sidebar tree of the root folder. key("n", "e", "", { noremap = true, silent = true, desc = "Open NeoTree without warnings", callback = function() vim.cmd("Neotree toggle source=filesystem position=left") end, }) -- Try to correct the current word. key("i", "", "ea", remap) -- Toggle built-in nvim spell checking. key("n", "", ":setlocal spell!", remap) -- Move lines normally like an IDE when line wraps key("i", "", [[v:count ? 'j' : 'gj']], { expr = true, noremap = true, silent = true }) key("i", "", [[v:count ? 'k' : 'gk']], { expr = true, noremap = true, silent = true }) key("n", "", [[v:count ? 'j' : 'gj']], { expr = true, noremap = true, silent = true }) key("n", "", [[v:count ? 'k' : 'gk']], { expr = true, noremap = true, silent = true }) -- Set 'CTRL + v' as 'paster' -- key('', '', 'map"_di', remap ) key("v", "", "p", remap) -- Set 'CTRL + x' as 'cut' key("v", "", "mad`ai", { silent = true }) -- Set 'CTRL + c' as 'copier' key("v", "", "may`ai", remap) key("i", "", ":Registers", remap) -- Set 'CTRL + s as save' key("n", "", "w", remap) -- Create mark. key("n", "'", "`", remap) -- Move normaly bottom and up with C+Up and C+Down. key("i", "", "gk", remap) key("i", "", "gj", remap) key("n", "", "gk", remap) key("n", "", "gj", remap) -- Set 'CTRL + z' as 'undo' key("i", "", "ui", remap) -- Set 'CTRL + y' as 'redo' key("i", "", "", remap) -- Set 'SHIFT + arrows' as 'select' like modern text-editor. key("n", "", "v", remap) key("n", "", "v", remap) key("n", "", "v", remap) key("n", "", "v", remap) key("v", "", "", remap) key("v", "", "", remap) key("v", "", "", remap) key("v", "", "", remap) key("i", "", "v", remap) key("i", "", "v", remap) key("i", "", "v", remap) key("i", "", "v", remap) -- Set 'SHIFT + special-keys' as 'select' like a modern text editor. key("i", "", "v", remap) key("i", "", "v", remap) key("n", "", "v", remap) key("n", "", "v", remap) key("n", "", "", remap) key("n", "", ":call Visual_Scroll_Down()i", remap) -- Indent the current visual selection. key("v", "<", "", ">gv", remap) -- Set 'Backspace' as 'delete selection' for the visual selection. key("v", "", '"_di', remap) --- -- Barbar keymappings local map = vim.api.nvim_set_keymap local opts = { noremap = true, silent = true } -- Move to previous/next map("n", "", "BufferPrevious", opts) map("n", "", "BufferNext", opts) -- Re-order to previous/next map("n", "", "BufferMovePrevious", opts) map("n", ">", "BufferMoveNext", opts) -- Goto buffer in position... map("n", "", "BufferGoto 1", opts) map("n", "", "BufferGoto 2", opts) map("n", "", "BufferGoto 3", opts) map("n", "", "BufferGoto 4", opts) map("n", "", "BufferGoto 5", opts) map("n", "", "BufferGoto 6", opts) map("n", "", "BufferGoto 7", opts) map("n", "", "BufferGoto 8", opts) map("n", "", "BufferGoto 9", opts) map("n", "", "BufferLast", opts) -- Pin/unpin buffer map("n", "", "BufferPin", opts) -- Close buffer -- map('n', '', 'BufferClose', opts) -- Wipeout buffer -- :BufferWipeout -- Close commands -- :BufferCloseAllButCurrent -- :BufferCloseAllButPinned -- :BufferCloseAllButCurrentOrPinned -- :BufferCloseBuffersLeft -- :BufferCloseBuffersRight -- Magic buffer-picking mode map("n", "", "BufferPick", opts) -- Sort automatically by... map("n", "bb", "BufferOrderByBufferNumber", opts) map("n", "bd", "BufferOrderByDirectory", opts) map("n", "bl", "BufferOrderByLanguage", opts) map("n", "bw", "BufferOrderByWindowNumber", opts) -- Other: -- :BarbarEnable - enables barbar (enabled by default) -- :BarbarDisable - very bad command, should never be used