nvim: keymappings: Enable unique and refactor/cleanup
Enable unique to detect and avoid conflicting key mappings.
This commit is contained in:
parent
6223b802ce
commit
97db1c6c9d
1 changed files with 92 additions and 90 deletions
|
@ -1,131 +1,133 @@
|
|||
local remap = vim.api.nvim_set_keymap
|
||||
local remap = vim.api.nvim_set_keymap
|
||||
local expr_opts = { noremap=true, silent=true, unique=true, expr=true }
|
||||
local opts = { noremap=true, silent=true, unique=true }
|
||||
|
||||
remap('c', '<Esc>', '<C-C>', { noremap = true })
|
||||
remap('c', '<Esc>', '<C-C>', opts)
|
||||
-- Use Q to execute default register.
|
||||
remap('n', 'Q', '<Nop>', { noremap = true })
|
||||
remap('n', 'Q', '<Nop>', opts)
|
||||
-- Save
|
||||
remap('n', '<Leader>w', '<Esc>:w<CR>', { noremap = true })
|
||||
remap('n', '<Leader>w', '<Esc>:w<CR>', opts)
|
||||
-- Copy to clipboard
|
||||
remap('v', '<Leader>y', '"+y', { noremap = true })
|
||||
remap('v', '<Leader>Y', '"*y', { noremap = true })
|
||||
remap('n', '<Leader>p', '<ESC>"+p', { noremap = true })
|
||||
remap('n', '<Leader>P', '<ESC>"*p', { noremap = true })
|
||||
remap('v', '<Leader>y', '"+y' , opts)
|
||||
remap('v', '<Leader>Y', '"*y' , opts)
|
||||
remap('n', '<Leader>p', '<ESC>"+p', opts)
|
||||
remap('n', '<Leader>P', '<ESC>"*p', opts)
|
||||
-- Search and Replace
|
||||
remap('n', 'c.', ':%s//g<Left><Left><CR>', { noremap = true })
|
||||
remap('n', '<Leader>c.', ':%s/\\<<C-r><C-w>\\>//g<Left><Left>', { noremap = true })
|
||||
remap('n', 'c.' , ':%s//g<Left><Left><CR>' , opts)
|
||||
remap('n', '<Leader>c.', ':%s/\\<<C-r><C-w>\\>//g<Left><Left>', opts)
|
||||
-- Quit
|
||||
remap('n', '<Leader>x', '<Esc>:x<CR>', { noremap = true })
|
||||
remap('n', '<Leader>q', '<Esc>:q<CR>', { noremap = true })
|
||||
remap('n', '<Leader>Q', '<Esc>:qa<CR>', { noremap = true })
|
||||
remap('n', '<Leader>x', '<Esc>:x<CR>' , opts)
|
||||
remap('n', '<Leader>q', '<Esc>:q<CR>' , opts)
|
||||
remap('n', '<Leader>Q', '<Esc>:qa<CR>', opts)
|
||||
-- Navigate buffers
|
||||
remap('n', '[b', ':bprevious<CR>', { noremap = true })
|
||||
remap('n', ']b', ':bnext<CR>', { noremap = true })
|
||||
remap('n', '[B', ':bfirst<CR>', { noremap = true })
|
||||
remap('n', ']B', ':blast<CR>', { noremap = true })
|
||||
remap('n', '[b', ':bprevious<CR>', opts)
|
||||
remap('n', ']b', ':bnext<CR>' , opts)
|
||||
remap('n', '[B', ':bfirst<CR>' , opts)
|
||||
remap('n', ']B', ':blast<CR>' , opts)
|
||||
-- Reload buffer
|
||||
remap('n', '<Leader>e', ':e<CR>', { noremap = true })
|
||||
remap('n', '<Leader>E', ':bufdo<CR>', { noremap = true })
|
||||
remap('n', '<Leader>e', ':e<CR>' , opts)
|
||||
remap('n', '<Leader>E', ':bufdo<CR>', opts)
|
||||
-- Tab navigation
|
||||
remap('n', '<Leader>tp', ':tabprevious<CR>', { noremap = true })
|
||||
remap('n', '<Leader>tn', ':tabnext<CR>', { noremap = true })
|
||||
remap('n', '<Leader>tf', ':tabfirst<CR>', { noremap = true })
|
||||
remap('n', '<Leader>tl', ':tablast<CR>', { noremap = true })
|
||||
remap('n', '<Leader>tN', ':tabnew<CR>', { noremap = true })
|
||||
remap('n', '<Leader>tc', ':tabclose<CR>', { noremap = true })
|
||||
remap('n', '<Leader>tp', ':tabprevious<CR>', opts)
|
||||
remap('n', '<Leader>tn', ':tabnext<CR>' , opts)
|
||||
remap('n', '<Leader>tf', ':tabfirst<CR>' , opts)
|
||||
remap('n', '<Leader>tl', ':tablast<CR>' , opts)
|
||||
remap('n', '<Leader>tN', ':tabnew<CR>' , opts)
|
||||
remap('n', '<Leader>tc', ':tabclose<CR>' , opts)
|
||||
-- Jump to first tab & close all other tabs. Helpful after running Git
|
||||
-- difftool.
|
||||
remap('n', '<Leader>T', ':tabfirst<CR>:tabonly<CR>', { noremap = true })
|
||||
remap('n', '<Leader>T', ':tabfirst<CR>:tabonly<CR>', opts)
|
||||
-- For tags
|
||||
remap('n', '[t', ':tprevious<CR>', { noremap = true })
|
||||
remap('n', ']t', ':tNext<CR>', { noremap = true })
|
||||
remap('n', '[T', ':tfirst<CR>', { noremap = true })
|
||||
remap('n', ']T', ':tlast<CR>', { noremap = true })
|
||||
remap('n', '<Leader>ts', ':<C-u>tselect <C-r><C-w><CR>', { noremap = true })
|
||||
remap('n', '[t', ':tprevious<CR>', opts)
|
||||
remap('n', ']t', ':tNext<CR>' , opts)
|
||||
remap('n', '[T', ':tfirst<CR>' , opts)
|
||||
remap('n', ']T', ':tlast<CR>' , opts)
|
||||
remap('n', '<Leader>ts', ':<C-u>tselect <C-r><C-w><CR>', opts)
|
||||
-- Quickfix list mappings
|
||||
remap('n', 'qo', ':copen<CR>', { noremap = true })
|
||||
remap('n', 'qc', ':cclose<CR>', { noremap = true })
|
||||
remap('n', '[q', ':cprevious<CR>', { noremap = true })
|
||||
remap('n', ']q', ':cnext<CR>', { noremap = true })
|
||||
remap('n', '[Q', ':cfirst<CR>', { noremap = true })
|
||||
remap('n', ']Q', ':clast<CR>', { noremap = true })
|
||||
remap('n', 'qo', ':copen<CR>' , opts)
|
||||
remap('n', 'qc', ':cclose<CR>' , opts)
|
||||
remap('n', '[q', ':cprevious<CR>', opts)
|
||||
remap('n', ']q', ':cnext<CR>' , opts)
|
||||
remap('n', '[Q', ':cfirst<CR>' , opts)
|
||||
remap('n', ']Q', ':clast<CR>' , opts)
|
||||
-- Location list mappings
|
||||
remap('n', 'Lo', ':lopen<CR>', { noremap = true })
|
||||
remap('n', 'Lc', ':lclose<CR>', { noremap = true })
|
||||
remap('n', '[l', ':lprevious<CR>', { noremap = true })
|
||||
remap('n', ']l', ':lnext<CR>', { noremap = true })
|
||||
remap('n', '[L', ':lfirst<CR>', { noremap = true })
|
||||
remap('n', ']L', ':lfirst<CR>', { noremap = true })
|
||||
remap('n', 'Lo', ':lopen<CR>' , opts)
|
||||
remap('n', 'Lc', ':lclose<CR>' , opts)
|
||||
remap('n', '[l', ':lprevious<CR>', opts)
|
||||
remap('n', ']l', ':lnext<CR>' , opts)
|
||||
remap('n', '[L', ':lfirst<CR>' , opts)
|
||||
remap('n', ']L', ':lfirst<CR>' , opts)
|
||||
-- Preview tags
|
||||
remap('n', 'pt', ':ptag <C-R><C-W><CR>', { noremap = true })
|
||||
remap('n', '[p', ':ptprevious<CR>', { noremap = true })
|
||||
remap('n', ']p', ':ptnext<CR>', { noremap = true })
|
||||
remap('n', 'po', ':ppop<CR>', { noremap = true })
|
||||
remap('n', 'pc', ':pc<CR>', { noremap = true })
|
||||
remap('n', 'pi', ':psearch <C-R><C-W><CR>', { noremap = true })
|
||||
remap('n', 'pt', ':ptag <C-R><C-W><CR>' , opts)
|
||||
remap('n', '[p', ':ptprevious<CR>' , opts)
|
||||
remap('n', ']p', ':ptnext<CR>' , opts)
|
||||
remap('n', 'po', ':ppop<CR>' , opts)
|
||||
remap('n', 'pc', ':pc<CR>' , opts)
|
||||
remap('n', 'pi', ':psearch <C-R><C-W><CR>', opts)
|
||||
-- Short cuts for setting fold methods
|
||||
remap('n', 'zmi', ':set foldmethod=indent<CR>', { noremap = true })
|
||||
remap('n', 'zmm', ':set foldmethod=manual<CR>', { noremap = true })
|
||||
remap('n', 'zme', ':set foldmethod=expr<CR>', { noremap = true })
|
||||
remap('n', 'zmk', ':set foldmethod=marker<CR>', { noremap = true })
|
||||
remap('n', 'zms', ':set foldmethod=syntax<CR>', { noremap = true })
|
||||
remap('n', 'zmi', ':set foldmethod=indent<CR>', opts)
|
||||
remap('n', 'zmm', ':set foldmethod=manual<CR>', opts)
|
||||
remap('n', 'zme', ':set foldmethod=expr<CR>' , opts)
|
||||
remap('n', 'zmk', ':set foldmethod=marker<CR>', opts)
|
||||
remap('n', 'zms', ':set foldmethod=syntax<CR>', opts)
|
||||
|
||||
-- Key Bindings to help with terminal mode
|
||||
remap('t', '<Esc>', '<C-\\><C-n>', { noremap = true })
|
||||
remap('t', '<Esc>', '<C-\\><C-n>', opts)
|
||||
|
||||
-- Key bindings to move between window splits
|
||||
remap('n', '<Space>0', '0<C-w>w', { noremap = true })
|
||||
remap('n', '<Space>1', '1<C-w>w', { noremap = true })
|
||||
remap('n', '<Space>2', '2<C-w>w', { noremap = true })
|
||||
remap('n', '<Space>3', '3<C-w>w', { noremap = true })
|
||||
remap('n', '<Space>4', '4<C-w>w', { noremap = true })
|
||||
remap('n', '<Space>5', '5<C-w>w', { noremap = true })
|
||||
remap('n', '<Space>6', '6<C-w>w', { noremap = true })
|
||||
remap('n', '<Space>7', '7<C-w>w', { noremap = true })
|
||||
remap('n', '<Space>8', '8<C-w>w', { noremap = true })
|
||||
remap('n', '<Space>9', '9<C-w>w', { noremap = true })
|
||||
remap('n', '<Space>0', '0<C-w>w', opts)
|
||||
remap('n', '<Space>1', '1<C-w>w', opts)
|
||||
remap('n', '<Space>2', '2<C-w>w', opts)
|
||||
remap('n', '<Space>3', '3<C-w>w', opts)
|
||||
remap('n', '<Space>4', '4<C-w>w', opts)
|
||||
remap('n', '<Space>5', '5<C-w>w', opts)
|
||||
remap('n', '<Space>6', '6<C-w>w', opts)
|
||||
remap('n', '<Space>7', '7<C-w>w', opts)
|
||||
remap('n', '<Space>8', '8<C-w>w', opts)
|
||||
remap('n', '<Space>9', '9<C-w>w', opts)
|
||||
|
||||
-- Tag helpers
|
||||
remap('n', '<C-\\>', ':vsp <CR>:<C-u>tag <C-r><C-w><CR>', { noremap = true })
|
||||
remap('n', '<A-]>', ':sp <CR>:<C-u>tag <C-r><C-w><CR>', { noremap = true })
|
||||
remap('n', '<C-\\>', ':vsp <CR>:<C-u>tag <C-r><C-w><CR>', opts)
|
||||
remap('n', '<A-]>' , ':sp <CR>:<C-u>tag <C-r><C-w><CR>' , opts)
|
||||
|
||||
remap('n', '<Leader>n', ':nohlsearch<CR>', { noremap = true, silent = true })
|
||||
remap('n', '<Leader>h', ':help<SPACE>', { noremap = true })
|
||||
remap('n', '<Leader>n', ':nohlsearch<CR>', opts)
|
||||
remap('n', '<Leader>h', ':help<SPACE>' , opts)
|
||||
|
||||
-- Move across wrapped lines like regular lines
|
||||
-- Go to the first non-blank character of a line
|
||||
remap('n', '0', '^', { noremap = true })
|
||||
remap('n', '0', '^', opts)
|
||||
-- Just in case you need to go to the very beginning of a line
|
||||
remap('n', '^', '0', { noremap = true })
|
||||
remap('n', '^', '0', opts)
|
||||
|
||||
-- Make dot work on visually selected lines
|
||||
remap('v', '.', ':norm.<CR>', { noremap = true })
|
||||
remap('v', '.', ':norm.<CR>', opts)
|
||||
-- Go to the last file we changed
|
||||
remap('n', '<BS>', '<C-^>', { noremap = true })
|
||||
remap('n', '<BS>', '<C-^>', opts)
|
||||
|
||||
-- Use Tab & S-Tab instead of C-g and C-t for incsearch
|
||||
remap('c', '<Tab>', 'getcmdtype() =~ \'[?/]\' ? \'<C-g>\' : feedkeys(\'<Tab>\', \'int\')[1]', { noremap = true, expr = true })
|
||||
remap('c', '<S-Tab>', 'getcmdtype() =~ \'[?/]\' ? \'<C-t>\' : feedkeys(\'<S-Tab>\', \'int\')[1]', { noremap = true, expr = true })
|
||||
remap('c', '<Tab>' , 'getcmdtype() =~ \'[?/]\' ? \'<C-g>\' : feedkeys(\'<Tab>\' , \'int\')[1]', expr_opts)
|
||||
remap('c', '<S-Tab>', 'getcmdtype() =~ \'[?/]\' ? \'<C-t>\' : feedkeys(\'<S-Tab>\', \'int\')[1]', expr_opts)
|
||||
|
||||
remap('n', '<F1>', ':call SyntaxAttr#SyntaxAttr()<CR>', { noremap = true })
|
||||
remap('n', '<F2>', ':TSHighlightCapturesUnderCursor<CR>', { noremap = true })
|
||||
remap('n', '<F1>', ':call SyntaxAttr#SyntaxAttr()<CR>' , opts)
|
||||
remap('n', '<F2>', ':TSHighlightCapturesUnderCursor<CR>', opts)
|
||||
|
||||
-- After shifting a visual block, select it again
|
||||
remap('v', '<', '<gv', { noremap = true })
|
||||
remap('v', '>', '>gv', { noremap = true })
|
||||
remap('v', '<', '<gv', opts)
|
||||
remap('v', '>', '>gv', opts)
|
||||
|
||||
-- Select last pasted/yanked text
|
||||
remap('n', 'g<C-v>', '`[v`]', { noremap = true })
|
||||
remap('n', 'g<C-v>', '`[v`]', opts)
|
||||
|
||||
-- Map ;; to :
|
||||
remap('n', ';;', ':', { noremap = true })
|
||||
remap('n', ';;', ':', opts)
|
||||
|
||||
-- https://vim.fandom.com/wiki/Moving_lines_up_or_down
|
||||
remap('n', '<A-j>', ':m .+1<CR>==', { noremap = true, silent = true })
|
||||
remap('n', '<A-k>', ':m .-2<CR>==', { noremap = true, silent = true })
|
||||
remap('i', '<A-j>', '<ESC>:m .+1<CR>==gi', { noremap = true, silent = true })
|
||||
remap('i', '<A-k>', '<ESC>:m .-2<CR>==gi', { noremap = true, silent = true })
|
||||
remap('v', '<A-j>', ':m \'>+1<CR>gv=gv', { noremap = true, silent = true })
|
||||
remap('v', '<A-k>', ':m \'<-2<CR>gv=gv', { noremap = true, silent = true })
|
||||
remap('n', '<A-j>', ':m .+1<CR>==' , opts)
|
||||
remap('n', '<A-k>', ':m .-2<CR>==' , opts)
|
||||
remap('i', '<A-j>', '<ESC>:m .+1<CR>==gi', opts)
|
||||
remap('i', '<A-k>', '<ESC>:m .-2<CR>==gi', opts)
|
||||
remap('v', '<A-j>', ':m \'>+1<CR>gv=gv' , opts)
|
||||
remap('v', '<A-k>', ':m \'<-2<CR>gv=gv' , opts)
|
||||
|
||||
-- Marks
|
||||
-- '0 - Position of cursor when last exited Vim.
|
||||
|
@ -138,6 +140,6 @@ remap('v', '<A-k>', ':m \'<-2<CR>gv=gv', { noremap = true, silent = true })
|
|||
-- 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', '<Leader>mc', ':norm `.<CR>', { noremap = true })
|
||||
remap('n', '<Leader>mi', ':norm `^<CR>', { noremap = true })
|
||||
remap('n', '<Leader>mj', ':norm `\'<CR>', { noremap = true })
|
||||
remap('n', '<Leader>mc', ':norm `.<CR>' , opts)
|
||||
remap('n', '<Leader>mi', ':norm `^<CR>' , opts)
|
||||
remap('n', '<Leader>mj', ':norm `\'<CR>', opts)
|
||||
|
|
Loading…
Reference in a new issue