neovim-config/lua/macbook/keybindings.lua

49 lines
1.5 KiB
Lua

local function map(m, k, v)
vim.keymap.set(m, k, v, { silent = true })
end
-- Fix * (keep the cursor position, don't move to next match)
-- map('n', '*', '*N')
-- Fix n and N. This keeps cursor always in the center when jumping between next and previous matches.
map('n', 'n', 'nzz')
map('n', 'N', 'Nzz')
-- Mimic shell movements
map('i', '<C-E>', '<C-o>$')
map('i', '<C-A>', '<C-o>^')
-- Quickly save the current buffer or all buffers
map('n', '<leader>w', '<CMD>update<CR>')
map('n', '<leader>W', '<CMD>wall<CR>')
-- Quit neovim
map('n', '<C-Q>', '<CMD>q<CR>')
-- leader-o/O inserts blank line below/above. Comes in handly when inserting blank lines between code blocks.
map('n', '<leader>o', 'o<ESC>')
map('n', '<leader>O', 'O<ESC>')
-- Move to the next/previous buffer
map('n', '<leader>[', '<CMD>bp<CR>')
map('n', '<leader>]', '<CMD>bn<CR>')
-- Move to the last buffer (CTRL-Tab style)
map('n', "''", '<CMD>b#<CR>')
-- Copying the vscode behaviour of making tab splits
map('n', '<C-\\>', '<CMD>vsplit<CR>')
map('n', '<A-\\>', '<CMD>split<CR>')
-- Move line up and down in NORMAL and VISUAL modes
-- Reference: https://vim.fandom.com/wiki/Moving_lines_up_or_down
map('n', '<C-j>', '<CMD>move .+1<CR>')
map('n', '<C-k>', '<CMD>move .-2<CR>')
map('x', '<C-j>', ":move '>+1<CR>gv=gv")
map('x', '<C-k>', ":move '<-2<CR>gv=gv")
-- Use operator pending mode to visually select the whole buffer
-- e.g. dA = delete buffer ALL, yA = copy whole buffer ALL
map('o', 'A', ':<C-U>normal! mzggVG<CR>`z')
map('x', 'A', ':<C-U>normal! ggVG<CR>')