2024-03-05 13:28:48 +01:00

74 lines
2.3 KiB
Lua

local function map(mode, lhs, rhs, info)
vim.keymap.set(mode, lhs, rhs, { desc = info })
end
-- Basics
map("n", ";", ":", "Command mode")
map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", "Clear search")
map({"n", "v"}, "<leader>q", "<cmd>qa!<cr>", "Quit all")
-- Buffer management
map("n", "<C-n>", "<cmd>enew<cr>", "New file")
map({ "i", "n", "s", "v" }, "<C-s>", "<cmd>w<cr>", "Save file")
map("n", "<C-q>", "<cmd>bd<cr>", "Delete buffer")
-- Copy and paste
map("v", "<C-c>", "y")
map("n", "<C-v>", '"+P<right>')
-- Editing lines
map({ "n", "v" }, "<C-b>", "^", "Beginning of line")
map("i", "<C-b>", "<esc>^i", "Beginning of line")
map({ "i", "n", "v" }, "<C-e>", "<end>", "End of line")
map("n", "<C-l>", "^Da", "Rewrite line")
map("i", "<C-l>", "<esc>^Da", "Rewrite line")
map("v", "<C-l>", "V", "Select line")
map("n", "<C-Enter>", "i<Enter>", "Split line")
map({"n", "v"}, "<C-a>", "<esc>ggVG", "Select all")
-- Editing multiple instances
map("n", "<f3>", "*#", "Search word under cursor")
map("v", "<f3>", "y/<C-r>\"<cr>N", "Search selection")
map("n", "<C-d>", "viw", "Select word under cursor")
map("v", "<C-d>", "y/<C-r>\"<cr>N", "Search selection")
map("n", "<C-r>", "*#:%s//<C-r><C-w>/g<left><left>", "Replace word under cursor")
map("v", "<C-r>", "y/<C-r>\"<cr>N:%s//<C-r>\"/g<left><left>", "Replace selection")
-- Editing words
map("n", "<C-w>", "ciw", "Rewrite word")
map("n", "<Bslash>", "<cmd>ToggleWord<cr>", "Toggle word")
-- Indenting
map("n", "<Tab>", "V>gv<esc>")
map("n", "<S-Tab>", "V<gv<esc>")
map("v", "<Tab>", ">gv")
map("v", "<S-Tab>", "<gv")
-- Increasing and decreasing numbers
map("n", "+", "<C-a>", "Increase number")
map("n", "-", "<C-x>", "Decrease number")
map("n", "<kPlus>", "<C-a>", "Increase number")
map("n", "<kMinus>", "<C-x>", "Decrease number")
-- Package manager
map("n", "<leader>l", "<cmd>Lazy<cr>", "Lazy")
-- Redo
map("n", "U", "<cmd>redo<cr>", "Redo")
-- Shift arrow selection
map("n", "<S-Up>", "v<Up>")
map("n", "<S-Down>", "v<Down>")
map("n", "<S-Left>", "v<Left>")
map("n", "<S-Right>", "v<Right>")
map("v", "<S-Up>", "<Up>")
map("v", "<S-Down>", "<Down>")
map("v", "<S-Left>", "<Left>")
map("v", "<S-Right>", "<Right>")
map("i", "<S-Up>", "<Esc>v<Up>")
map("i", "<S-Down>", "<Esc>v<Down>")
map("i", "<S-Left>", "<Esc>v<Left>")
map("i", "<S-Right>", "<Esc>v<Right>")