-- 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 local keyset = vim.keymap.set local function map_nv(lhs, rhs, opts) local modes = { "n", "v" } for _, mode in ipairs(modes) do keyset(mode, lhs, rhs, opts) end end local function map_all_mode(lhs, rhs, opts) map_nv(lhs, rhs, opts) keyset("i", lhs, rhs, opts) keyset("t", lhs, rhs, opts) end -- Very fundamnetal changes for basic vanila Vim. Each change in this section need explanation. -- Making c key less disruptive to normal coppying and pasting map_nv("c", '"1c', { desc = "Change and put the deleted part into secondary clipboard" }) map_nv("C", '"1C', { desc = "Change and put the deleted part into secondary clipboard" }) -- Commented otherwise we could not use xp to interchange map_nv("x", '"1x', { desc = "Delete and put the deleted part into secondary clipboard" }) map_nv("X", '"1X', { desc = "Delete and put the deleted part into secondary clipboard" }) map_nv("", '"1d', { desc = "Delete and put the deleted part into secondary clipboard" }) keyset("n", "", '"1d', { noremap = true, desc = "Backspace in normal mode" }) keyset("o", "", 'd', { noremap = true, desc = "Backspace in normal mode" }) --TODO: This does not work due to which-key keyset({ "x", "v" }, "", '"1x', { noremap = true, desc = "Backspace in normal mode" }) -- keyset("v", "x", '"_x', { noremap = true, desc = "Delete without saving to clipboard" }) --Config lsp vimtex keymaps -- TODO: make this workqq -- vim.keymap.set("n", "ls", function() -- vim.b.vimtex_main = vim.fn.expand("%:p") -- vim.cmd("VimtexReloadState") -- end, { noremap = true, desc = "Set current buffer as vimtex main" }) -- Config Dap keymaps map_all_mode("", function() require("dap").continue() end, { desc = "Dap: Continue" }) map_all_mode("", function() require("dap").run_last() end, { desc = "Dap: Use last config" }) map_all_mode("", function() require("dap").step_over() end, { desc = "Dap: Step Over" }) map_all_mode("", function() require("dap").step_into() end, { desc = "Dap: Step Into" }) map_all_mode("", function() require("dap").step_out() end, { desc = "Dap: Step Out" }) keyset("n", "dv", function() vim.cmd("DapVirtualTextToggle") end, { desc = "Toggle virtual text of dap" }) keyset("n", "b", function() require("dap").toggle_breakpoint() end, { desc = "Dap: Toggle Breakpoint" }) keyset("n", "dr", function() require("dap").repl.open() end, { desc = "Dap: Open REPL" }) keyset({ "n", "v" }, "dh", function() require("dap.ui.widgets").hover() end, { desc = "Print variable (Hover Mode)" }) keyset({ "n", "v" }, "dp", function() require("dap.ui.widgets").preview() end, { desc = "Print variable (Preview Mode)" }) -- Configure Coc.nvim keymaps keyset("n", "r", "(coc-rename)", { desc = "Rename (Coc)" }) keyset("v", "r", "(coc-codeaction-refactor-selected)", { desc = "Refactor Selected (Coc)" }) keyset("n", "cl", "(coc-codelens-action)", { desc = "CodeLens Action (Coc)" }) keyset("n", "ca", "(coc-codeaction)", { desc = "Code Action (Coc)" }) keyset("v", "ca", "(coc-codeaction-selected)", { desc = "Code Action (Coc)" }) -- Resolve Coc conflicting keymaps keyset({ "i", "c" }, "", "^", { desc = "Goto beginning" }) keyset({ "i", "c" }, "", "$", { desc = "Goto end" }) -- Now configure shortcuts for MacOS -- if vim.g.neovide then keyset("n", "", "(YankyPreviousEntry)") keyset("n", "", "(YankyNextEntry)") map_all_mode("", "w") -- Save map_all_mode("", function() local success, _ = pcall(function() vim.cmd("tabclose") end) if not success then vim.notify("Cannot close the last tab page", vim.log.levels.WARN) end end, { desc = "Close current tab" }) map_all_mode("", function() vim.cmd("undo") end) keyset("i", "", '"+P') keyset("c", "", "+") keyset("n", "", '"+p', { desc = "Paste from clipboard" }) keyset("v", "", '"1d"+gP', { desc = "Remove the selected part and paste from system clipboard." }) keyset("v", "", '"+y', { desc = "Copy to clipboard in visual mode" }) keyset("v", "", '"+d', { desc = "Cut to clipboard" }) map_nv("", "ggG", { desc = "Select all" }) -- Test: Code action Menu vim.keymap.set("n", "m", function() require("tiny-code-action").code_action() end, { noremap = true, silent = true })