dotfiles/nvim/.config/nvim/keymappings.vim
Sanchayan Maity c42e841e3e nvim: Switch to vim-sneak
Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
2020-05-27 15:15:32 +05:30

151 lines
4.6 KiB
VimL

" Allow saving of files as sudo when I forgot to start vim using sudo
cmap w!! w !sudo tee > /dev/null %
" 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>
" Jump and change list
nnoremap <Leader>o :call GotoJump()<CR>
nnoremap <Leader>; :changes<CR>:keepjumps norm g;<Left><Left>
nnoremap <Leader>, :changes<CR>:keepjumps norm g,<Left><Left>
" Async Make mappings
nnoremap <LocalLeader>b :Make<CR>
nnoremap <LocalLeader>B :LMake<CR>
" For Fuzzy
nnoremap <Leader>b :Buffers<CR>
nnoremap <Leader>/ :GFiles?<CR>
nnoremap <Leader>ff :GFiles<CR>
nnoremap <Leader>fF :Files<CR>
nnoremap <Leader>fL :Lines<CR>
nnoremap <Leader>fl :BLines<CR>
nnoremap <Leader>ft :BTags<CR>
nnoremap <Leader>fT :Tags<CR>
nnoremap <Leader>fc :BCommits<CR>
nnoremap <Leader>fC :Commits<CR>
nnoremap <Leader>fh :History:<CR>
nnoremap <Leader>fH :History/<CR>
nnoremap <Leader>fm :Commands<CR>
nnoremap <Leader>fo :Locate<SPACE>
nnoremap <Leader>fk :Maps<CR>
nnoremap <Leader>f/ :Rg<CR>
nnoremap <Leader>fs :exe ':Rg ' . expand('<cword>')<CR>
imap <C-x><C-w> <Plug>(fzf-complete-word)
imap <C-x><C-p> <Plug>(fzf-complete-path)
imap <C-x><C-f> <Plug>(fzf-complete-file)
imap <C-x><C-l> <Plug>(fzf-complete-line)
" Save
nnoremap <Leader>w <Esc>:w<CR>
" Search and Replace
nnoremap sr :%s//g<Left><Left>
nnoremap <Leader>sr :%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>
nnoremap [t :tabprevious<CR>
nnoremap ]t :tabnext<CR>
nnoremap [T :tabfirst<CR>
nnoremap ]T :tablast<CR>
" For git
nnoremap <Leader>gm :GitMessenger<CR>
nnoremap ]c :GitGutterNextHunk<CR>
nnoremap [c :GitGutterPrevHunk<CR>
nnoremap ghs :GitGutterStageHunk<CR>
nnoremap ghu :GitGutterUndoHunk<CR>
nnoremap ghp :GitGutterPreviewHunk<CR>
nnoremap ghq :GitGutterQuickFix<CR>
nnoremap ghf :GitGutterFold<CR>
omap ih <Plug>(GitGutterTextObjectInnerPending)
omap ah <Plug>(GitGutterTextObjectOuterPending)
xmap ih <Plug>(GitGutterTextObjectInnerVisual)
xmap ah <Plug>(GitGutterTextObjectOuterVisual)
" For workspace
nnoremap <Leader>ws :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 qs :Grep<SPACE>
nnoremap q* :Grep <cword><CR>
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 Ls :LGrep<SPACE>
nnoremap L* :LGrep <cword><CR>
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> :ToggleTerminal<Enter>
tnoremap <silent> <C-z> <C-\><C-n>:ToggleTerminal<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>
" 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
" Make dot work on visually selected lines
vnoremap . :norm.<CR>
" Go to the last file we changed
nnoremap <BS> <C-^>
" For nvim-completion
imap <C-j> <cmd>lua require'source'.prevCompletion()<CR>
imap <C-k> <cmd>lua require'source'.nextCompletion()<CR>
" Asynchronous make
command! -bang -nargs=* -complete=file Make call asyncdo#run(<bang>0, &makeprg, <f-args>)
command! -bang -nargs=* -complete=file LMake call asyncdo#lrun(<bang>0, &makeprg, <f-args>)