local function map(mode, lhs, rhs, opts) local options = { noremap = true } if opts then options = vim.tbl_extend('force', options, opts) end vim.keymap.set(mode, lhs, rhs, options) end local function nmap(lhs, rhs, opts) map('n', lhs, rhs, opts) end --- Mappings -- Essentials vim.g.mapleader = ' ' nmap(';', ':') map('v', ';', ':') nmap(',,', '') -- TODO: stop this madness, :h autowrite -- doesnt seem to work well in terminal nmap('w', ':w') nmap('Q', ':q!') nmap('', ':nohlsearch', { silent = true }) -- Convenience nmap('yy', 'Y') nmap('Y', 'y$') nmap('N', 'Nzz') nmap('n', 'nzz') nmap('j', 'gj') nmap('k', 'gk') nmap('H', '^') nmap('L', '$') nmap('J', 'mzJ`z') -- nmap('K', '') nmap('gQ', '') nmap('vv', ':vs') -- Tabs nmap('t', ':tabnew') nmap('', ':tabnext') nmap('', ':tabprevious') nmap('1', '1gt') nmap('2', '2gt') nmap('3', '3gt') nmap('4', '4gt') nmap('5', '5gt') -- Visual mode map('v', '.', ':normal .') map('v', 'J', ':m \'>+1gv=gv') map('v', 'K', ':m \'<-2gv=gv') map('v', '<', '', '>gv') -- vim-easy-align map("n", "ga", "(EasyAlign)") map("x", "ga", "(EasyAlign)") -- nvim-tree.lua -- nmap('n', ':NvimTreeToggle') -- nmap('N', ':NvimTreeFindFile') vim.keymap.set("n", "-", "Oil", { desc = "Open parent directory" }) -- glow.vim nmap('p', ':Glow') -- fugitive.vim nmap('ga', ':Gwrite') nmap('gs', ':Git') nmap('gb', ':Git blame') -- rails-vim nmap('a', ':A') -- test nmap('r', function() os.execute("tmux send-keys -t '{down-of}' './bin/rspec '" .. vim.fn.expand("%") .. " Enter") end) nmap('R', function() os.execute("tmux send-keys -t '{down-of}' './bin/rspec .' Enter") end) -- CtrlSF nmap('', 'CtrlSFPrompt') -- trim whitespace nmap('W', ':TrimWhitespace') -- EXPERIMENTAL: nmap('x', ":call delete(expand('%')) | bdelete!") nmap('q', ':copen') nmap(']q', ':cnext') nmap('[q', ':cprevious') -- command mode vim.keymap.set('c', '', '') vim.keymap.set('c', '', '') -- paste in visual mode and keep available local expr = { expr = true, noremap = false, silent = false } vim.keymap.set('x', 'p', [['pgv"'.v:register.'y`>']], expr) vim.keymap.set('x', 'P', [['Pgv"'.v:register.'y`>']], expr) -- vim.keymap.set('n', 'gQ', 'mzgggqG`zdelmarks zzz', { desc = 'Format buffer' }) vim.keymap.set('n', '', 'zz', { desc = 'Scroll downwards' }) vim.keymap.set('n', '', 'zz', { desc = 'Scroll upwards' }) -- vim.keymap.set('n', 'to', 'tabonly', { desc = 'Close other tab pages' }) -- Make U opposite to u. -- vim.keymap.set('n', 'U', '', { desc = 'Redo' })