home/.config/nvim/lua/keys.lua
2025-05-28 16:39:25 +02:00

67 lines
No EOL
2.3 KiB
Lua

vim.g.mapleader = " "
local function map(mode, lhs, rhs, info)
vim.keymap.set(mode, lhs, rhs, { desc = info })
end
-- Enter command mode without pressing shift
map("n", ";", ":", "Command mode")
-- Undo with u, Redo with U
map("n", "U", "<cmd>redo<cr>", "Redo")
-- Quit with q like any other terminal app
map({"n", "v"}, "q", "<cmd>qa<cr>", "Quit all")
map({"n", "v"}, "Q", "<cmd>qa!<cr>", "Force quit")
-- Clear search with Esc
map({"n", "i"}, "<esc>", "<cmd>noh<cr><esc>", "Clear search")
-- Ctrl S to save the file from any mode
map({"n", "i", "s", "v"}, "<C-s>", "<cmd>w<cr><esc>", "Save file")
-- Grab the line and move it up/down
map("n", "<C-j>", "<cmd>set paste<cr>m`O<esc>``<cmd>set nopaste<cr>", "Add empty line above")
map("n", "<C-k>", "m`<cmd>-g/\\m^\\s*$/d<cr>``<cmd>noh<cr>", "Delete empty line above")
-- Grab the line below and move it up/down
map("n", "<A-j>", "<cmd>set paste<cr>m`o<esc>``<cmd>set nopaste<cr>", "Add empty line below")
map("n", "<A-k>", "m`<cmd>+g/\\m^\\s*$/d<cr>``<cmd>noh<cr>", "Delete empty line below")
-- Horizontal movement
map({"n", "v"}, "H", "^", "Beginning of line")
map({"n", "v"}, "L", "<end>", "End of line")
-- Vertical movement
map({"n", "v"}, "J", "}", "Next paragraph")
map({"n", "v"}, "K", "{", "Previous paragraph")
-- Indenting
map("n", "<Tab>", "V>gv<esc>")
map("n", "<S-Tab>", "V<gv<esc>")
map("v", "<Tab>", ">gv")
map("v", "<S-Tab>", "<gv")
-- Toggle word
map("n", "<Bslash>", "<cmd>ToggleWord<cr>", "Toggle word")
-- 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")
-- Replace all 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")
-- Search all instances
map("n", "<f3>", "#*", "Search word under cursor")
map("v", "<f3>", "y/<C-r>\"<cr>N", "Search selection")
-- Window management
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")
map("n", "<A-q>", "<cmd>close<cr>", "Close window")