dotfiles/nvim/.config/nvim/keymappings.vim

136 lines
3.8 KiB
VimL

" Remap escape keys to something usable on home row
inoremap jk <Esc>
cnoremap jk <C-C>
inoremap <Esc> <Nop>
cnoremap <Esc> <Nop>
" Use Q to execute default register.
nnoremap Q <Nop>
" Save
nnoremap <Leader>w <Esc>:w<CR>
" Search and Replace
nnoremap c. :%s//g<Left><Left>
nnoremap <Leader>c. :%s/\<<C-r><C-w>\>//g<Left><Left>
" Quit
nnoremap <Leader>x <Esc>:x<CR>
nnoremap <Leader>q <Esc>:q<CR>
nnoremap <Leader>Q <Esc>:qa<CR>
" Navigate buffers
nnoremap [b :bprevious<CR>
nnoremap ]b :bnext<CR>
nnoremap [B :bfirst<CR>
nnoremap ]B :blast<CR>
" Reload buffer
nnoremap <Leader>e :e<CR>
nnoremap <Leader>E :bufdo e<CR>
" Tab navigation
nnoremap <Leader>tp :tabprevious<CR>
nnoremap <Leader>tn :tabnext<CR>
nnoremap <Leader>tf :tabfirst<CR>
nnoremap <Leader>tl :tablast<CR>
nnoremap <Leader>tN :tabnew<CR>
nnoremap <Leader>tc :tabclose<CR>
" For tags
nnoremap [t :tprevious<CR>
nnoremap ]t :tNext<CR>
nnoremap [T :tfirst<CR>
nnoremap ]T :tlast<CR>
nnoremap <Leader>ts :exec("tselect ".expand("<cword>"))<CR>
" For workspace
nnoremap <Leader>ps :ToggleWorkspace<CR>
" Quickfix & Location list mappings
nnoremap qo :copen<CR>
nnoremap qc :cclose<CR>
nnoremap [q :cprevious<CR>
nnoremap ]q :cnext<CR>
nnoremap [Q :cfirst<CR>
nnoremap ]Q :clast<CR>
nnoremap q* :Ggrep! <cword><CR>
nnoremap qs :Ggrep!<SPACE>
nnoremap qt :call ToggleQuickfixList()<CR>
nnoremap Lo :lopen<CR>
nnoremap Lc :lclose<CR>
nnoremap [l :lprevious<CR>
nnoremap ]l :lnext<CR>
nnoremap [L :lfirst<CR>
nnoremap ]L :llast<CR>
nnoremap L* :Glgrep! <cword><CR>
nnoremap Ls :Glgrep!<SPACE>
nnoremap Lt :call ToggleLocationList()<CR>
" Preview tags
nnoremap pt :ptag <C-R><C-W><CR>
nnoremap [p :ptprevious<CR>
nnoremap ]p :ptnext<CR>
nnoremap po :ppop<CR>
nnoremap pc :pc<CR>
nnoremap pi :psearch <C-R><C-W><CR>
" Short cuts for setting fold methods
nnoremap zmi :set foldmethod=indent<CR>
nnoremap zmm :set foldmethod=manual<CR>
nnoremap zme :set foldmethod=expr<CR>
nnoremap zmk :set foldmethod=marker<CR>
nnoremap zms :set foldmethod=syntax<CR>
" Key Bindings to help with terminal mode
tnoremap jk <C-\><C-n>
nnoremap <silent> <C-z> :FloatermToggle<Enter>
tnoremap <silent> <C-z> <C-\><C-n>:FloatermToggle<Enter>
" Key bindings to move between window splits
for key in range(0, 9)
execute 'nnoremap <Space>'.key key.'<C-w>w'
endfor
" Disable Arrow Keys
inoremap <Up> <NOP>
inoremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
" Whick key
nnoremap <silent> <Leader> :<C-U>WhichKey '<Space>'<CR>
nnoremap <silent> <LocalLeader> :<C-U>WhichKey ','<CR>
" Tag helpers
nnoremap <C-\> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
nnoremap <A-]> :sp <CR>:exec("tag ".expand("<cword>"))<CR>
" Use Tab & S-Tab instead of C-g and C-t for incsearch
cno <expr> <Tab> getcmdtype() =~ '[?/]' ? '<C-g>' : feedkeys('<Tab>', 'int')[1]
cno <expr> <S-Tab> getcmdtype() =~ '[?/]' ? '<C-t>' : feedkeys('<S-Tab>', 'int')[1]
nnoremap <silent> <Leader>n :nohlsearch<CR>
" Move across wrapped lines like regular lines
" Go to the first non-blank character of a line
noremap 0 ^
" Just in case you need to go to the very beginning of a line
noremap ^ 0
" Centre the window on each search movement
nnoremap n nzz
nnoremap N Nzz
vnoremap n nzz
vnoremap N Nzz
" Make dot work on visually selected lines
vnoremap . :norm.<CR>
" Go to the last file we changed
nnoremap <BS> <C-^>
nnoremap [i [I:call <SID>PromptAndExec(":ijump! %d \022\027\015")<CR>
nnoremap ]i ]I:call <SID>PromptAndExec(":+1,$ijump! %d \022\027\015")<CR>
function! s:PromptAndExec(cmd) abort
let ans = input('Type number and <Enter> (empty cancels): ')
if ans !~# '^\s*$'
try
silent execute 'normal! ' . printf(a:cmd, ans)
catch /E387/ "E387: Match is on current line
endtry
endif
endfunction