-- Keymaps are automatically loaded on the VeryLazy event -- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua -- Add any additional keymaps here -- TODO: these come from my old fennel config. I should definitely give them a second look -- Disable command history -- vim.keymap.set("n", "q:", ":q") -- creates a "wait time" if we plan to use q as quit -- Remap q (record macro) to Q local map = vim.keymap.set map("n", "q", "") map("n", "Q", "q") map("n", "", "") -- Helper function for which-key commands local function cmd_string(s) return "" .. s .. "" end -- Buffer navigation map("n", "h", cmd_string("bprevious"), { desc = "Previous buffer" }) map("n", "l", cmd_string("bnext"), { desc = "Next buffer" }) map("n", "", cmd_string("bprevious"), { desc = "Previous buffer" }) map("n", "", cmd_string("bnext"), { desc = "Next buffer" }) map("i", "", cmd_string("bprevious"), { desc = "Previous buffer" }) map("i", "", cmd_string("bnext"), { desc = "Next buffer" }) map("v", "", cmd_string("bprevious"), { desc = "Previous buffer" }) map("v", "", cmd_string("bnext"), { desc = "Next buffer" }) map("n", "", cmd_string("bdelete"), { desc = "Close buffer" }) -- Buffer management map("n", "bc", cmd_string("bdelete!"), { desc = "Close buffer" }) map("n", "bw", cmd_string("bwipeout!"), { desc = "Wipeout buffer" }) -- Close floating windows local function close_floating() for _, win in ipairs(vim.api.nvim_list_wins()) do local config = vim.api.nvim_win_get_config(win) if config.relative ~= "" then vim.api.nvim_win_close(win, false) end end end -- Use q and to close floating windows and clear search -- Already handled by LazyVim --map("n", "", function() -- close_floating() -- vim.cmd("nohlsearch") --end) -- --map("n", "q", function() -- close_floating() -- vim.cmd("nohlsearch") --end) -- Exit visual mode without relying on local function exit_visual_mode() vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "x", false) end -- Use q and to close floating windows and clear search in visual mode map("v", "", function() close_floating() vim.cmd("nohlsearch") exit_visual_mode() end) map("v", "q", function() close_floating() vim.cmd("nohlsearch") exit_visual_mode() end) -- Move up/down in menus with C-j and C-k map({ "i", "n", "c" }, "", "", { desc = "Move down" }) map({ "i", "n", "c" }, "", "", { desc = "Move up" }) -- Better indenting map("v", "<", "", ">gv", { desc = "Increase indent" }) -- Indenting in insert mode map("i", "", "", { desc = "Decrease indent" }) -- handled by mini.move map("v", "", ">gv", { desc = "Increase indent" }) map("v", "", "y", ""+y", { desc = "Copy (system)" }) -- map("v", "y", ""+y", { desc = "Copy (system)" }) -- map("n", "p", ""+p", { desc = "Paste (system)" }) -- map("v", "p", ""+p", { desc = "Paste (system)" }) -- Copy-paste with Ctrl-C and Ctrl-V -- map("v", "", ""+y", { desc = "Copy to system clipboard" }) -- BUG: C-c and esc are the same key -- map("n", "", ""+p", { desc = "Paste from system clipboard" }) -- TODO: Can"t use due to visual block issues map("i", "", "'+p", { desc = "Paste from system clipboard" }) map("v", "", "'+p", { desc = "Paste from system clipboard" }) -- Unmap default keybinds related to code (lsp) vim.keymap.del("n", "cd") vim.keymap.del("n", "cf") vim.keymap.del("n", "cm") vim.keymap.del("n", "cs") vim.keymap.del("n", "cS") -- Unmap saving vim.keymap.del("n", "") vim.keymap.del("i", "") vim.keymap.del("v", "") -- diagnostic local diagnostic_goto = function(next, severity) local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev severity = severity and vim.diagnostic.severity[severity] or nil return function() go({ severity = severity }) end end map("n", "gd", vim.diagnostic.open_float, { desc = "Line Diagnostics" }) map("n", "]d", diagnostic_goto(true), { desc = "Next Diagnostic" }) map("n", "[d", diagnostic_goto(false), { desc = "Prev Diagnostic" }) map("n", "]e", diagnostic_goto(true, "ERROR"), { desc = "Next Error" }) map("n", "[e", diagnostic_goto(false, "ERROR"), { desc = "Prev Error" }) map("n", "]w", diagnostic_goto(true, "WARN"), { desc = "Next Warning" }) map("n", "[w", diagnostic_goto(false, "WARN"), { desc = "Prev Warning" }) map("n", "C", function() local result = vim.treesitter.get_captures_at_cursor(0) print(vim.inspect(result)) end, { noremap = true, silent = false, desc = "Get highlight group under cursor" } ) -- Fix for Telescope"s race condition with default C-F map("n", "", LazyVim.pick("files"), { noremap = true, silent = false })