--[[ 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. --]] -- luacheck: globals vim CAPABILITIES local wk = require("which-key") -- ╭──────────────────────────────────────────────────────────╮ -- │ Register keybindings │ -- ╰──────────────────────────────────────────────────────────╯ -- ╭──────────────────────────────────────────────────────────╮ -- │ Register in all modes, prefix │ -- ╰──────────────────────────────────────────────────────────╯ wk.register({ b = { name = "+buffer", n = { "tabnew", "[n]ew tab" }, a = { name = "+annotate", -- defined in plugins/neogen.lua }, 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", }, }, t = { ":TabnineToggle", "Toggle TabNine" }, }, D = { name = "+Diagnostics (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" }, --- x = { function() require("trouble").open() end, "Open Trouble" }, w = { function() require("trouble").open("workspace_diagnostics") end, "Workspace diagnostics" }, d = { function() require("trouble").open("document_diagnostics") end, "Document diagnostics" }, q = { function() require("trouble").open("quickfix") end, "Quickfix" }, l = { function() require("trouble").open("loclist") end, "Loclist" }, r = { function() require("trouble").open("lsp_references") end, "LSP References" }, }, e = { function() vim.cmd("Neotree focus source=filesystem position=left") end, "Toggle the sidebar tree", }, f = { name = "+find", -- 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 = "+harpoon", 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 = "+help/Conceal/Treesitter", c = { name = "+conceal", 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" }, }, }, o = { g = { -- defined in plugins/gitsigns.lua name = "+git", b = { name = "+blame", }, }, }, p = { name = "+plugins", i = { function() require("lazy").install() end, "plugins [i]nstall" }, s = { function() require("lazy").home() end, "plugins [s]tatus" }, S = { function() require("lazy").sync() end, "plugins [S]ync" }, u = { function() require("lazy").check() end, "plugins Check [u]pdates" }, U = { function() require("lazy").update() end, "plugins [U]pdate" }, }, q = { name = "+quit", q = { ":qa", "quit: [q]uit all" }, f = { ":qa!", "quit: all with [f]orce" }, }, r = { -- defined in plugins/refactoring-nvim.lua name = "+refactor", }, t = { name = "+telescope", -- Find recursively TODOs, NOTEs, FIXITs, ... across the root folder subfiles. t = { ":TodoTelescope", "[t]elescope: [t]odo" }, }, x = { ":Bdelete", "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 = "" }) -- -- ╭──────────────────────────────────────────────────────────╮ -- │ Insert mode, no prefix │ -- ╰──────────────────────────────────────────────────────────╯ wk.register({ [""] = { "w", "Save file" }, [""] = { "", "Do just Home on CTRL + Home" }, }, { mode = "i", prefix = "" }) -- -- ╭──────────────────────────────────────────────────────────╮ -- │ All modes, no prefix │ -- ╰──────────────────────────────────────────────────────────╯ wk.register({ [""] = { "w", "Save file" }, [""] = { "", "Do just End on CTRL + End" }, }, { prefix = "" }) -- -- ╭──────────────────────────────────────────────────────────╮ -- │ Other keymappings, still to move │ -- ╰──────────────────────────────────────────────────────────╯ local key = vim.api.nvim_set_keymap local remap = { noremap = true, silent = true } -- Go to the next block. --key('n', '', 'g%', remap ) -- Loop through brackets blocks. --key('n', '', 'z%', 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 }) -- 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) -- Indent the current visual selection. key("v", "<", "", ">gv", remap) -- Set 'Backspace' as 'delete selection' for the visual selection. key("v", "", '"_di', remap)