2024-06-21 16:42:08 +02:00

68 lines
2.5 KiB
Lua

local function map(mode, lhs, rhs, info)
vim.keymap.set(mode, lhs, rhs, { desc = info })
end
map("n", ";", ":", "Command mode")
map("n", "U", "<cmd>redo<cr>", "Redo")
map("n", "<Bslash>", "<cmd>ToggleWord<cr>", "Toggle word")
map("n", "<C-q>", "<cmd>close<cr>", "Close window")
map("n", "<leader>l", "<cmd>Lazy<cr>", "Lazy")
map({"n", "v"}, "<leader>q", "<cmd>qa!<cr>", "Quit all")
map({"n", "i"}, "<esc>", "<cmd>noh<cr><esc>", "Clear search")
map({"n", "i", "s", "v"}, "<C-s>", "<cmd>w<cr><esc>", "Save file")
-- Add or delete empty lines
map("n", "<C-j>", "<cmd>set paste<cr>m`o<esc>``<cmd>set nopaste<cr>", "Add empty line below")
map("n", "<C-k>", "<cmd>set paste<cr>m`O<esc>``<cmd>set nopaste<cr>", "Add empty line above")
map("n", "<A-j>", "m`<cmd>+g/\\m^\\s*$/d<cr>``<cmd>noh<cr>", "Delete empty line below")
map("n", "<A-k>", "m`<cmd>-g/\\m^\\s*$/d<cr>``<cmd>noh<cr>", "Delete empty line above")
-- Quick movement
map("n", "J", "}", "Next paragraph")
map("n", "K", "{", "Previous paragraph")
-- Editing multiple instances
map("n", "<f2>", "*#:%s//<C-r><C-w>/g<left><left>", "Replace word under cursor")
map("v", "<f2>", "y/<C-r>\"<cr>N:%s//<C-r>\"/g<left><left>", "Replace selection")
map("n", "<f3>", "#*", "Search word under cursor")
map("v", "<f3>", "y/<C-r>\"<cr>N", "Search selection")
-- Line movement
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")
-- 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")
-- Indenting
map("n", "<Tab>", "V>gv<esc>")
map("n", "<S-Tab>", "V<gv<esc>")
map("v", "<Tab>", ">gv")
map("v", "<S-Tab>", "<gv")
-- 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>")
-- Window switching
map("n", "<A-Up>", "<C-w>k", "Move to the window above")
map("n", "<A-Down>", "<C-w>j", "Move to the window below")
map("n", "<A-Left>", "<C-w>h", "Move to the window on the left")
map("n", "<A-Right>", "<C-w>l", "Move to the window on the right")