local remap = vim.api.nvim_set_keymap local expr_opts = { noremap=true, unique=true, expr=true } local silent_opts = { noremap=true, unique=true, silent=true } local opts = { noremap=true, unique=true } remap('c', '', '', opts) remap('n', '', ':noh', opts) -- Use Q to execute default register. remap('n', 'Q', '', opts) -- Copy to clipboard remap('v', 'y', '"+y' , opts) remap('v', 'Y', '"*y' , opts) remap('n', 'p', '"+p', opts) remap('n', 'P', '"*p', opts) -- Search and Replace remap('n', 'c.' , ':%s//g' , opts) remap('n', 'c.', ':%s/\\<\\>//g', opts) -- Exact Search remap('n', 'S', '/\\<\\>', opts) -- Quit remap('n', 'x', ':x' , opts) remap('n', 'q', ':q' , opts) remap('n', 'Q', ':qa', opts) -- Navigate buffers remap('n', '[b', ':bprevious', opts) remap('n', ']b', ':bnext' , opts) remap('n', '[B', ':bfirst' , opts) remap('n', ']B', ':blast' , opts) -- Reload buffer remap('n', 'e', ':e' , opts) remap('n', 'E', ':bufdo', opts) -- Tab navigation remap('n', 'tp', ':tabprevious', opts) remap('n', 'tn', ':tabnext' , opts) remap('n', 'tf', ':tabfirst' , opts) remap('n', 'tl', ':tablast' , opts) remap('n', 'tN', ':tabnew' , opts) remap('n', 'tc', ':tabclose' , opts) -- Jump to first tab & close all other tabs. Helpful after running Git -- difftool. remap('n', 'T', ':tabfirst:tabonly', opts) -- Quickfix list mappings remap('n', 'qo', ':copen' , opts) remap('n', 'qc', ':cclose' , opts) remap('n', '[q', ':cprevious', opts) remap('n', ']q', ':cnext' , opts) remap('n', '[Q', ':cfirst' , opts) remap('n', ']Q', ':clast' , opts) -- Location list mappings remap('n', 'Lo', ':lopen' , opts) remap('n', 'Lc', ':lclose' , opts) remap('n', '[l', ':lprevious', opts) remap('n', ']l', ':lnext' , opts) remap('n', '[L', ':lfirst' , opts) remap('n', ']L', ':lfirst' , opts) -- Short cuts for setting fold methods remap('n', 'zmi', ':set foldmethod=indent', opts) remap('n', 'zmm', ':set foldmethod=manual', opts) remap('n', 'zme', ':set foldmethod=expr' , opts) remap('n', 'zmk', ':set foldmethod=marker', opts) remap('n', 'zms', ':set foldmethod=syntax', opts) -- Key Bindings to help with terminal mode remap('t', '', '', opts) -- Key bindings to move between window splits remap('n', '0', '0w', opts) remap('n', '1', '1w', opts) remap('n', '2', '2w', opts) remap('n', '3', '3w', opts) remap('n', '4', '4w', opts) remap('n', '5', '5w', opts) remap('n', '6', '6w', opts) remap('n', '7', '7w', opts) remap('n', '8', '8w', opts) remap('n', '9', '9w', opts) -- Move across wrapped lines like regular lines -- Go to the first non-blank character of a line remap('n', '0', '^', opts) -- Just in case you need to go to the very beginning of a line remap('n', '^', '0', opts) -- Make dot work on visually selected lines remap('v', '.', ':norm.', opts) -- Go to the last file we changed remap('n', '', '', opts) -- Use Tab & S-Tab instead of C-g and C-t for incsearch remap('c', '' , 'getcmdtype() =~ \'[?/]\' ? \'\' : feedkeys(\'\' , \'int\')[1]', expr_opts) remap('c', '', 'getcmdtype() =~ \'[?/]\' ? \'\' : feedkeys(\'\', \'int\')[1]', expr_opts) -- Use arrow keys to navigate in popup menu remap('c', '' , 'pumvisible() ? feedkeys(\'\', \'int\')[1] : \'\'' , expr_opts) remap('c', '', 'pumvisible() ? feedkeys(\'\' , \'int\')[1] : \'\'', expr_opts) remap('n', '', ':TSHighlightCapturesUnderCursor', opts) -- After shifting a visual block, select it again remap('v', '<', '', '>gv', opts) -- Select last pasted/yanked text remap('n', 'g', '`[v`]', opts) -- Map ;; to : remap('n', ';;', ':', opts) -- https://vim.fandom.com/wiki/Moving_lines_up_or_down remap('n', '', ':m .+1==' , opts) remap('n', '', ':m .-2==' , opts) remap('i', '', ':m .+1==gi', opts) remap('i', '', ':m .-2==gi', opts) remap('v', '', ':m \'>+1gv=gv' , opts) remap('v', '', ':m \'<-2gv=gv' , opts) -- Marks -- '0 - Position of cursor when last exited Vim. -- '" - Position of cursor when last exited the current buffer. -- '. - Position of last change. -- '< & '> - Start/end of visual selection. -- '[ & '] - Start/end of last change or yank. -- '^ - Position of cursor when last Vim last left insert mode - This is how gi command works. -- '' - Position before last jump (Super useful!). See :h ''. -- Map gm to `. Instead of `a, hit gma. See :help mark-motions as to why we use backtick. remap('n', 'gm', '`', { noremap = false }) -- Jump using marks to last change, left insert, jump. remap('n', 'mc', ':norm `.' , opts) remap('n', 'mi', ':norm `^' , opts) remap('n', 'mj', ':norm `\'', opts) remap('n', '[d', 'lua vim.diagnostic.goto_prev { wrap = false }' , opts) remap('n', ']d', 'lua vim.diagnostic.goto_next { wrap = false }' , opts) remap('n', '[D', 'lua vim.diagnostic.goto_prev()' , opts) remap('n', ']D', 'lua vim.diagnostic.goto_next()' , opts) remap('n', 'dl', 'lua vim.diagnostic.setloclist()' , opts) remap('n', 'dq', 'lua vim.diagnostic.setqflist()' , opts) remap('n', 'dr', 'lua vim.diagnostic.reset()' , opts) remap('n', 'dH', 'lua vim.diagnostic.hide()' , opts) remap('n', 'dh', 'lua vim.diagnostic.show()' , opts) remap('n', ',d', 'lua vim.diagnostic.open_float(0, {scope="line"})' , opts) remap('n', ',D', 'lua vim.diagnostic.open_float(0, {scope="cursor"})', opts) -- DiffConflicts remap('n', 'dc', ':DiffConflicts' , opts) remap('n', 'ds', ':DiffConflictsShowHistory', opts) remap('n', 'dw', ':DiffConflictsWithHistory', opts) -- Tmux pane and nvim window switching remap('n', '' , ':TmuxNavigateLeft' , silent_opts) remap('n', '', ':TmuxNavigateRight', silent_opts) remap('n', '' , ':TmuxNavigateUp' , silent_opts) remap('n', '' , ':TmuxNavigateDown' , silent_opts)