starter/lua/config/keymaps.lua

105 lines
3.6 KiB
Lua
Raw Normal View History

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-05-25 07:48:16 +08:00
local function map_nv(lhs, rhs, opts)
local modes = { "n", "v" }
for _, mode in ipairs(modes) do
vim.keymap.set(mode, lhs, rhs, opts)
end
end
local function map_all_mode(lhs, rhs, opts)
map_nv(lhs, rhs, opts)
vim.keymap.set("i", lhs, rhs, opts)
2025-05-26 06:39:08 +08:00
vim.keymap.set("t", lhs, rhs, opts)
2025-05-25 07:48:16 +08:00
end
2025-05-26 06:39:08 +08:00
-- TODO: make this work
vim.keymap.set("v", "x", '"_x', { noremap = true, desc = "Delete selection with Backspace" })
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-05-25 07:48:16 +08:00
vim.keymap.set("n", "\\b", function()
require("dap").toggle_breakpoint()
2025-05-27 10:01:40 +08:00
end, { desc = "Dap: Toggle Breakpoint" })
vim.keymap.set("n", "\\dr", function()
require("dap").repl.open()
end, { desc = "Dap: Open REPL" })
vim.keymap.set({ "n", "v" }, "\\dh", function()
require("dap.ui.widgets").hover()
end, { desc = "Print variable (Hover Mode)" })
vim.keymap.set({ "n", "v" }, "\\dp", function()
require("dap.ui.widgets").preview()
end, { desc = "Print variable (Preview Mode)" })
-- TODO: remove this
-- vim.keymap.set("n", "\\dt", function()
-- require("dapui").toggle()
-- end, { desc = "Toggle debug GUI" })
-- vim.keymap.set({ "n", "v" }, "\\de", function()
-- require("dapui").eval()
-- end, { desc = "Eval variable" })
2025-05-25 10:35:43 +08:00
2025-05-26 06:39:08 +08:00
-- Now configure shortcuts for MacOS
-- if vim.g.neovide then
vim.keymap.set("n", "<D-s>", ":w<CR>") -- Save
vim.keymap.set("i", "<D-s>", "<C-O>:w<CR>")
map_all_mode("<D-w>", 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("<D-z>", function() vim.cmd("undo") end)
2025-05-26 12:24:00 +08:00
vim.keymap.set("i", "<D-v>", '<C-O>"+p')
vim.keymap.set("c", "<D-v>", "<C-R>+")
2025-05-26 06:39:08 +08:00
vim.keymap.set("n", "<D-v>", '"+p', { desc = "Paste from clipboard" })
vim.keymap.set("v", "<D-v>", '"_d"+gP', { desc = "Remove the selected part and paste from system clipboard." })
2025-05-26 06:39:08 +08:00
vim.keymap.set("v", "<D-c>", '"+y', { desc = "Copy to clipboard in visual mode" })
vim.keymap.set("v", "<D-x>", '"+d', { desc = "Cut to clipboard" })
map_nv("<D-a>", "gg<S-v>G", { desc = "Select all" })
-- end
2025-05-27 04:00:43 +08:00
-- Set the keymap <leader>fg to trigger the picker
2025-05-27 10:01:40 +08:00
-- vim.keymap.set("n", "<leader>fg", function()
-- local Snacks = require("snacks")
-- return Snacks.picker({
-- finder = "lsp_symbols", -- Use the LSP symbols as the source
-- layout = {
-- layout = {
-- box = "horizontal",
-- width = 0.5,
-- height = 0.5,
-- {
-- box = "vertical",
-- border = "rounded",
-- title = "Find directory",
-- { win = "input", height = 1, border = "bottom" },
-- { win = "list", border = "none" },
-- },
-- },
-- },
-- format = 'lsp_symbol',
-- confirm = function(picker, item)
-- picker:close()
-- Snacks.picker.pick("files", {
-- dirs = { item.file },
-- })
-- end,
-- filter = {
-- tex = true,
-- }
-- })
-- end
-- , { desc = "Find LaTeX environments using LSP" }) -- Updated description