--- Personal keymaps — custom workflow shortcuts. --- Includes text selection helpers, file management (save, quit, source), --- number increment/decrement, buffer management with smart close via --- snacks.bufdelete, coding shortcuts (React import, semicolons, commas, --- console.log), Copilot Chat commands, clipboard HTML-to-Markdown paste, --- and quickfix/location list navigation. --- @module keymaps.personal local keymap = vim.keymap -- ============================================================================= -- PERSONAL KEYMAPS (ORIGINAL WORKFLOW) -- ============================================================================= --- Select the entire file contents (visual mode). keymap.set("n", "u", function() vim.cmd("normal! ggVG$") end, { desc = "Select the whole file" }) --- Duplicate the current line below. keymap.set("n", "4", function() -- Copy current line and paste below vim.cmd("normal! yy") vim.cmd("normal! p") end, { desc = "Copy the entire line and paste just below" }) --- File management — save, quit, force quit, source, and clear search. keymap.set("n", "w", ":w", { desc = "Save the current file" }) keymap.set("n", "xa", ":xa", { desc = "Save and close all the files" }) keymap.set("n", "q", ":q", { desc = "Quit" }) keymap.set("n", "so", ":source %", { desc = "Reload nvim" }) keymap.set("n", "no", ":noh ", { desc = "Reset search a word" }) --- Increment/decrement the number under the cursor. keymap.set("n", "+", "", { desc = "Increment number" }) keymap.set("n", "-", "", { desc = "Decrement number" }) -- Window management keymaps are centralized in lua/cargdev/core/keymaps/window.lua --- Re-indent the entire file using Neovim's built-in `=` operator. keymap.set("n", "sy", "gg=G", { desc = "Format current file" }) --- Fast scroll — 10 lines at a time with Ctrl+E / Ctrl+Y. keymap.set("n", "", "10", { noremap = true, silent = true }) keymap.set("n", "", "10", { noremap = true, silent = true }) --- Close the current buffer with a confirmation prompt if modified. keymap.set("n", "bd", function() if vim.bo.modified then vim.ui.select({ "Save & Close", "Discard & Close", "Cancel" }, { prompt = "Buffer has unsaved changes:", }, function(choice) if choice == "Save & Close" then vim.cmd("w") vim.cmd("bd") elseif choice == "Discard & Close" then vim.cmd("bd!") end end) else vim.cmd("bd") end end, { desc = "Buffer: Close (safe)" }) --- Force close the current buffer, discarding unsaved changes. keymap.set("n", "bD", ":db!", { desc = "Buffer: Force close" }) --- Buftabline navigation — Ctrl+P next buffer, Ctrl+N previous buffer. keymap.set("n", "", ":bnext", { noremap = true, silent = true }) keymap.set("n", "", ":bprev", { noremap = true, silent = true }) --- Coding shortcuts — React import, trailing comma/semicolon, run with Node. keymap.set( "n", "re", "ggOimportReactfrom'react';0", { desc = "Type import react from 'react' at the top of the file" } ) keymap.set("n", ",", "$a,", { desc = "Adding ',' at the end of the line" }) keymap.set("n", ";", "$a;", { desc = "Adding ';' at the end of the line" }) keymap.set("n", "xr", ":!node %", { desc = "Run file with node" }) -- Resize splits keymaps are centralized in lua/cargdev/core/keymaps/window.lua --- Copilot Chat — rename, explain, review, fix, optimize, and generate docs. keymap.set("v", "zn", ":CopilotChatRename", { desc = "Rename variable (Copilot Chat)" }) keymap.set("n", "zc", ":CopilotChat", { desc = "Open Copilot Chat" }) keymap.set("v", "ze", ":CopilotChatExplain", { desc = "Explain code (Copilot Chat)" }) keymap.set("v", "zr", ":CopilotChatReview", { desc = "Review code (Copilot Chat)" }) keymap.set("v", "zf", ":CopilotChatFix", { desc = "Fix code issues (Copilot Chat)" }) keymap.set("v", "zo", ":CopilotChatOptimize", { desc = "Optimize code (Copilot Chat)" }) keymap.set("v", "zd", ":CopilotChatDocs", { desc = "Generate docs (Copilot Chat)" }) --- Paste HTML from the system clipboard as GitHub-Flavored Markdown (via pandoc). --- TODO: Fix this keymap -- keymap.set("n", "p", function() -- vim.cmd("read !pbpaste -Prefer html | pandoc -f html -t gfm") -- end, { desc = "Paste HTML clipboard as Markdown" }) -- ============================================================================= -- QUICKFIX NAVIGATION (under x for Trouble/Diagnostics group) -- ============================================================================= --- Quickfix list navigation — next, previous, open, close, first, last. keymap.set("n", "xn", ":cnextzz", { desc = "Quickfix: Next item" }) keymap.set("n", "xp", ":cprevzz", { desc = "Quickfix: Previous item" }) keymap.set("n", "xo", ":copen", { desc = "Quickfix: Open list" }) keymap.set("n", "xq", ":cclose", { desc = "Quickfix: Close list" }) keymap.set("n", "xf", ":cfirstzz", { desc = "Quickfix: First item" }) keymap.set("n", "xl", ":clastzz", { desc = "Quickfix: Last item" }) --- Location list navigation — next, previous, open, close. keymap.set("n", "ln", ":lnextzz", { desc = "Location: Next item" }) keymap.set("n", "lp", ":lprevzz", { desc = "Location: Previous item" }) keymap.set("n", "lo", ":lopen", { desc = "Location: Open list" }) keymap.set("n", "lq", ":lclose", { desc = "Location: Close list" })