-- Shorten function name local keymap = vim.keymap.set -- Silent keymap option local opts = { noremap = true, silent = true } --Remap space as leader key keymap("", "", "", opts) vim.g.mapleader = " " -- Modes -- normal_mode = "n", -- insert_mode = "i", -- visual_mode = "v", -- visual_block_mode = "x", -- term_mode = "t", -- command_mode = "c", -- -- Apply q macro keymap("n", "", "@q", vim.tbl_extend("force", opts, { desc = "Run default macro" })) -- Kitty navigation vim.g.kitty_navigator_no_mappings = 1 keymap("n", "", ":KittyNavigateLeft", vim.tbl_extend("force", opts, { desc = "Navigate left" })) keymap("n", "", ":KittyNavigateDown", vim.tbl_extend("force", opts, { desc = "Navigate down" })) keymap("n", "", ":KittyNavigateUp", vim.tbl_extend("force", opts, { desc = "Navigate up" })) keymap("n", "", ":KittyNavigateRight", vim.tbl_extend("force", opts, { desc = "Navigate right" })) -- Resize with arrows keymap("n", "", ":resize -2", vim.tbl_extend("force", opts, { desc = "Window horizontal resize -2" })) keymap("n", "", ":resize +2", vim.tbl_extend("force", opts, { desc = "Window horizontal resize +2" })) keymap( "n", "", ":vertical resize -2", vim.tbl_extend("force", opts, { desc = "Window vertical resize -2" }) ) keymap( "n", "", ":vertical resize +2", vim.tbl_extend("force", opts, { desc = "Window vertical resize +2" }) ) -- Navigate buffers keymap( "n", "", ":bnext", vim.tbl_extend("force", opts, { desc = "Navigate to the next buffer on the right" }) ) keymap( "n", "", ":bprevious", vim.tbl_extend("force", opts, { desc = "Navigate to the previous buffer on the left" }) ) -- Clear highlights keymap("n", "h", "nohlsearch", vim.tbl_extend("force", opts, { desc = "Clear search highlights" })) -- Close buffers keymap("n", "", "Bdelete!", vim.tbl_extend("force", opts, { desc = "Close buffer" })) -- LSP / Diagnostics keymap( "n", "xx", "Trouble diagnostics toggle", vim.tbl_extend("force", opts, { desc = "Toggle trouble diganostics" }) ) keymap( "n", "xd", "Trouble diagnostics toggle filter.buf=0", vim.tbl_extend("force", opts, { desc = "Toggle trouble buffer diganostics" }) ) keymap( "n", "K", "Lspsaga hover_doc", vim.tbl_extend("force", opts, { desc = "Show a hover window with the documentation" }) ) keymap( "n", "E", "Lspsaga show_line_diagnostics", vim.tbl_extend("force", opts, { desc = "Show a hover window with the diagnostics of the error" }) ) keymap( "n", "gd", "Lspsaga finder", vim.tbl_extend("force", opts, { desc = "Show a hover window with the usage of the directive under the cursor" }) ) keymap( "n", "ld", "Lspsaga goto_definition", vim.tbl_extend("force", opts, { desc = "Navigate to the definition of the directive under the cursor" }) ) keymap( "n", "la", "Lspsaga code_action", vim.tbl_extend("force", opts, { desc = "Show available code actions for the line under the cursor" }) ) keymap( "n", "lj", "Lspsaga diagnostic_jump_next", vim.tbl_extend("force", opts, { desc = "Navigate to the next diagnostic in the buffer" }) ) keymap( "n", "lk", "Lspsaga diagnostic_jump_prev", vim.tbl_extend("force", opts, { desc = "Navigate to the previous diagnostic in the buffer" }) ) keymap( "n", "lr", "Lspsaga rename mode=n", vim.tbl_extend("force", opts, { desc = "Open a dialog to rename a code element" }) ) keymap( "n", "lp", "Lspsaga peek_definition", vim.tbl_extend("force", opts, { desc = "Peek the definition of the directive under the cursor" }) ) keymap({ "n", "v" }, "lf", function() require("conform").format({ async = true, lsp_fallback = true }) end, vim.tbl_extend("force", opts, { desc = "Format the current buffer or selection" })) -- Neotest keymap( "n", "tr", "RunTest", vim.tbl_extend("force", opts, { desc = "Run test on the current function" }) ) keymap( "n", "tf", "RunTestFile", vim.tbl_extend("force", opts, { desc = "Run tests on the current file" }) ) -- Copilot keymap({ "n", "v" }, "coh", function() local actions = require("CopilotChat.actions") require("CopilotChat.integrations.telescope").pick(actions.help_actions()) end, vim.tbl_extend("force", opts, { desc = "CopilotChat - Help actions" })) keymap({ "n", "v" }, "cop", function() local actions = require("CopilotChat.actions") require("CopilotChat.integrations.telescope").pick(actions.prompt_actions()) end, vim.tbl_extend("force", opts, { desc = "CopilotChat - Prompt actions" })) keymap("n", "coq", function() local input = vim.fn.input("Quick Chat: ") if input ~= "" then require("CopilotChat").ask(input, { selection = require("CopilotChat.select").buffer }) end end, vim.tbl_extend("force", opts, { desc = "CopilotChat - Quick chat" })) -- Better paste keymap("v", "p", "P", vim.tbl_extend("force", opts, { desc = "Paste" })) -- Press jk fast to exit insert mode keymap("i", "jk", "", vim.tbl_extend("force", opts, { desc = "Exit insert mode" })) -- Stay in indent mode keymap("v", "<", "", ">gv", opts) -- NeoTree keymap("n", "e", ":Neotree toggle", vim.tbl_extend("force", opts, { desc = "Toggle Neotree" })) keymap( "n", "gg", ":Neotree float git_status", vim.tbl_extend("force", opts, { desc = "Open a float window with the git status" }) ) -- Telescope keymap( "n", "ff", ":Telescope find_files", vim.tbl_extend("force", opts, { desc = "Open a Telescope prompt to search for files" }) ) keymap( "n", "", ":Telescope find_files", vim.tbl_extend("force", opts, { desc = "Open a Telescope prompt to search for files" }) ) keymap( "n", "fg", ":Telescope live_grep", vim.tbl_extend("force", opts, { desc = "Open a Telescope prompt to search for text in all files" }) ) keymap( "n", "fk", ":Telescope keymaps", vim.tbl_extend("force", opts, { desc = "Open a Telescope prompt to show all keymaps" }) ) keymap( "n", "fc", ":Telescope commands", vim.tbl_extend("force", opts, { desc = "Open a Telescope prompt to show all commands" }) ) -- Comment keymap( "n", "/", "lua require'Comment.api'.toggle.linewise.current()", vim.tbl_extend("force", opts, { desc = "Comment/Uncomment code lines" }) ) keymap( "x", "/", "lua require'Comment.api'.toggle.linewise(vim.fn.visualmode())", vim.tbl_extend("force", opts, { desc = "Comment/Uncomment code lines on visual block mode" }) ) -- Gitdiff keymap( "n", "df", ":DiffviewFileHistory %", vim.tbl_extend("force", opts, { desc = "Open diff view file history for the current buffer" }) ) keymap("n", "dc", ":DiffviewClose", vim.tbl_extend("force", opts, { desc = "Close diff view" })) -- Projects keymap( "n", "fp", ":Telescope neovim-project discover", vim.tbl_extend("force", opts, { desc = "Open a Telescope prompt to search for projects" }) ) -- Base64 keymap( "v", "64e", ":lua require'b64'.encode()", vim.tbl_extend("force", opts, { desc = "Encode the visual selected text to base64" }) ) keymap( "v", "64d", ":lua require'b64'.decode()", vim.tbl_extend("force", opts, { desc = "Decode the visual selected text from base64" }) ) -- Illuminate keymap( "n", "", "lua require'illuminate'.next_reference{wrap=true}", vim.tbl_extend("force", opts, { desc = "Navigate to the next selected text by illuminate" }) ) keymap( "n", "", "lua require'illuminate'.next_reference{reverse=true,wrap=true}", vim.tbl_extend("force", opts, { desc = "Navigate to the previous selected text by illuminate" }) ) -- Folding keymap( "n", "zR", "lua require'ufo'.openAllFolds()", vim.tbl_extend("force", opts, { desc = "Open all folds" }) ) keymap( "n", "zM", "lua require'ufo'.closeAllFolds()", vim.tbl_extend("force", opts, { desc = "Close all folds" }) ) keymap( "n", "zr", "lua require'ufo'.openFoldsExceptKinds()", vim.tbl_extend("force", opts, { desc = "Fold less" }) ) keymap("n", "zm", "lua require'ufo'.closeFoldsWith()", vim.tbl_extend("force", opts, { desc = "Fold more" })) keymap( "n", "zp", "lua require'ufo'.peekFoldedLinesUnderCursor()", vim.tbl_extend("force", opts, { desc = "Peek fold" }) ) -- Markdown keymap( "n", "m", ":RenderMarkdown toggle", vim.tbl_extend("force", opts, { desc = "Toggle markdown rendering" }) )