2023-01-07 17:52:40 +08:00
|
|
|
-- 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
|
2025-06-05 00:52:34 +08:00
|
|
|
local keyset = vim.keymap.set
|
2025-05-25 07:48:16 +08:00
|
|
|
local function map_nv(lhs, rhs, opts)
|
|
|
|
local modes = { "n", "v" }
|
|
|
|
for _, mode in ipairs(modes) do
|
2025-06-05 00:52:34 +08:00
|
|
|
keyset(mode, lhs, rhs, opts)
|
2025-05-25 07:48:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
local function map_all_mode(lhs, rhs, opts)
|
|
|
|
map_nv(lhs, rhs, opts)
|
2025-06-05 00:52:34 +08:00
|
|
|
keyset("i", lhs, rhs, opts)
|
|
|
|
keyset("t", lhs, rhs, opts)
|
2025-05-25 07:48:16 +08:00
|
|
|
end
|
2025-06-13 05:21:40 +08:00
|
|
|
-- 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" })
|
2025-06-14 04:19:05 +08:00
|
|
|
map_nv("C", '"1C', { desc = "Change and put the deleted part into secondary clipboard" })
|
|
|
|
-- Commented otherwise we could not use xp to interchange
|
2025-06-13 05:21:40 +08:00
|
|
|
map_nv("x", '"1x', { desc = "Delete and put the deleted part into secondary clipboard" })
|
2025-06-14 04:19:05 +08:00
|
|
|
map_nv("X", '"1X', { desc = "Delete and put the deleted part into secondary clipboard" })
|
|
|
|
map_nv("<C-d>", '"1d', { desc = "Delete and put the deleted part into secondary clipboard" })
|
2025-06-13 05:21:40 +08:00
|
|
|
keyset("n", "<BS>", '"1d', { noremap = true, desc = "Backspace in normal mode" })
|
2025-06-15 07:27:46 +08:00
|
|
|
keyset("o", "<BS>", "d", { noremap = true, desc = "Backspace in normal mode" })
|
2025-06-14 04:19:05 +08:00
|
|
|
--TODO: This does not work due to which-key
|
|
|
|
keyset({ "x", "v" }, "<BS>", '"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", "<locallleader>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
|
2025-05-25 07:48:16 +08:00
|
|
|
map_all_mode("<F5>", function()
|
|
|
|
require("dap").continue()
|
2025-05-27 10:01:40 +08:00
|
|
|
end, { desc = "Dap: Continue" })
|
2025-05-25 10:35:43 +08:00
|
|
|
map_all_mode("<F6>", function()
|
|
|
|
require("dap").run_last()
|
2025-05-27 10:01:40 +08:00
|
|
|
end, { desc = "Dap: Use last config" })
|
2025-05-25 07:48:16 +08:00
|
|
|
map_all_mode("<F10>", function()
|
|
|
|
require("dap").step_over()
|
2025-05-27 10:01:40 +08:00
|
|
|
end, { desc = "Dap: Step Over" })
|
2025-05-25 07:48:16 +08:00
|
|
|
map_all_mode("<F11>", function()
|
|
|
|
require("dap").step_into()
|
2025-05-27 10:01:40 +08:00
|
|
|
end, { desc = "Dap: Step Into" })
|
2025-05-25 07:48:16 +08:00
|
|
|
map_all_mode("<F12>", function()
|
|
|
|
require("dap").step_out()
|
2025-05-27 10:01:40 +08:00
|
|
|
end, { desc = "Dap: Step Out" })
|
2025-06-05 00:52:34 +08:00
|
|
|
keyset("n", "<leader>dv", function()
|
|
|
|
vim.cmd("DapVirtualTextToggle")
|
|
|
|
end, { desc = "Toggle virtual text of dap" })
|
2025-06-14 04:19:05 +08:00
|
|
|
keyset("n", "<localleader>b", function()
|
2025-05-25 07:48:16 +08:00
|
|
|
require("dap").toggle_breakpoint()
|
2025-05-27 10:01:40 +08:00
|
|
|
end, { desc = "Dap: Toggle Breakpoint" })
|
2025-06-14 04:19:05 +08:00
|
|
|
keyset("n", "<localleader>dr", function()
|
2025-05-27 10:01:40 +08:00
|
|
|
require("dap").repl.open()
|
|
|
|
end, { desc = "Dap: Open REPL" })
|
2025-06-14 04:19:05 +08:00
|
|
|
keyset({ "n", "v" }, "<localleader>dh", function()
|
2025-05-27 10:01:40 +08:00
|
|
|
require("dap.ui.widgets").hover()
|
|
|
|
end, { desc = "Print variable (Hover Mode)" })
|
2025-06-14 04:19:05 +08:00
|
|
|
keyset({ "n", "v" }, "<localleader>dp", function()
|
2025-05-27 10:01:40 +08:00
|
|
|
require("dap.ui.widgets").preview()
|
|
|
|
end, { desc = "Print variable (Preview Mode)" })
|
2025-05-25 10:35:43 +08:00
|
|
|
|
2025-06-04 07:54:28 +08:00
|
|
|
-- Configure Coc.nvim keymaps
|
2025-06-14 04:19:05 +08:00
|
|
|
keyset("n", "<localleader>r", "<Plug>(coc-rename)", { desc = "Rename (Coc)" })
|
|
|
|
keyset("v", "<localleader>r", "<Plug>(coc-codeaction-refactor-selected)", { desc = "Refactor Selected (Coc)" })
|
|
|
|
keyset("n", "<localleader>cl", "<Plug>(coc-codelens-action)", { desc = "CodeLens Action (Coc)" })
|
2025-06-15 07:27:46 +08:00
|
|
|
-- Code actions are actually twisted by another plugin
|
2025-06-14 04:19:05 +08:00
|
|
|
keyset("n", "<localleader>ca", "<Plug>(coc-codeaction)", { desc = "Code Action (Coc)" })
|
|
|
|
keyset("v", "<localleader>ca", "<Plug>(coc-codeaction-selected)", { desc = "Code Action (Coc)" })
|
2025-06-04 07:54:28 +08:00
|
|
|
|
2025-06-05 08:34:57 +08:00
|
|
|
-- Resolve Coc conflicting keymaps
|
2025-06-14 04:19:05 +08:00
|
|
|
keyset({ "i", "c" }, "<C-a>", "<C-o>^", { desc = "Goto beginning" })
|
|
|
|
keyset({ "i", "c" }, "<C-e>", "<C-o>$", { desc = "Goto end" })
|
2025-06-04 07:54:28 +08:00
|
|
|
|
2025-05-26 06:39:08 +08:00
|
|
|
-- Now configure shortcuts for MacOS
|
|
|
|
-- if vim.g.neovide then
|
2025-06-13 05:21:40 +08:00
|
|
|
keyset("n", "<c-p>", "<Plug>(YankyPreviousEntry)")
|
|
|
|
keyset("n", "<c-n>", "<Plug>(YankyNextEntry)")
|
2025-06-05 08:34:57 +08:00
|
|
|
map_all_mode("<D-s>", "<Cmd>w<CR>") -- Save
|
2025-05-26 06:39:08 +08:00
|
|
|
map_all_mode("<D-w>", function()
|
2025-06-05 08:34:57 +08:00
|
|
|
local success, _ = pcall(function()
|
|
|
|
vim.cmd("tabclose")
|
|
|
|
end)
|
2025-05-26 06:39:08 +08:00
|
|
|
if not success then
|
|
|
|
vim.notify("Cannot close the last tab page", vim.log.levels.WARN)
|
|
|
|
end
|
|
|
|
end, { desc = "Close current tab" })
|
2025-06-05 08:34:57 +08:00
|
|
|
map_all_mode("<D-z>", function()
|
|
|
|
vim.cmd("undo")
|
|
|
|
end)
|
2025-06-05 00:52:34 +08:00
|
|
|
keyset("i", "<D-v>", '<C-O>"+P')
|
|
|
|
keyset("c", "<D-v>", "<C-R>+")
|
|
|
|
keyset("n", "<D-v>", '"+p', { desc = "Paste from clipboard" })
|
2025-06-14 04:19:05 +08:00
|
|
|
keyset("v", "<D-v>", '"1d"+gP', { desc = "Remove the selected part and paste from system clipboard." })
|
2025-06-05 00:52:34 +08:00
|
|
|
keyset("v", "<D-c>", '"+y', { desc = "Copy to clipboard in visual mode" })
|
|
|
|
keyset("v", "<D-x>", '"+d', { desc = "Cut to clipboard" })
|
2025-05-26 06:39:08 +08:00
|
|
|
map_nv("<D-a>", "gg<S-v>G", { desc = "Select all" })
|
2025-06-15 13:16:34 +08:00
|
|
|
if vim.env.ALACRITTY_SOCKET then
|
|
|
|
keyset("n", "<C-Tab>", ":BufferLineCycleNext<CR>", { silent = true })
|
|
|
|
keyset("n", "<C-S-Tab>", ":BufferLineCyclePrev<CR>", { silent = true })
|
2025-06-25 10:02:23 +08:00
|
|
|
keyset("i", "<C-Tab>", function()
|
|
|
|
require("copilot.suggestion").accept()
|
|
|
|
end, { silent = true, desc = "Copilot Accept Suggestion" })
|
2025-06-15 13:16:34 +08:00
|
|
|
end
|
2025-06-15 07:27:46 +08:00
|
|
|
-- Code action menu
|
|
|
|
vim.keymap.set({ "n", "v" }, "<leader>ca", function()
|
|
|
|
---@diagnostic disable-next-line: missing-parameter
|
2025-06-15 04:20:33 +08:00
|
|
|
require("tiny-code-action").code_action()
|
|
|
|
end, { noremap = true, silent = true })
|