" common typo fixes command! WQ wq command! Wq wq command! Wqa wqa command! W w command! Q q " best leader let mapleader = "\" " enter insert mode when entering a terminal buffer augroup InsertModeOnBlankTerminal autocmd BufWinEnter,WinEnter term://* startinsert augroup END " terminal mappings nnoremap t :split term://$SHELL:resize 24i nnoremap :split term://$SHELL:resize 24i nnoremap t :vsplit term://$SHELL:vertical resize 120i " nnoremap :vsplit term://$SHELL:vertical resize 120i nnoremap :vsplit term://$SHELL:vertical resize 120i " close the terminal tnoremap :q! tnoremap w :q! " tnoremap tnoremap " moving between terminal splits tnoremap :TmuxNavigateLeft tnoremap :TmuxNavigateDown tnoremap :TmuxNavigateUp tnoremap :TmuxNavigateRight " Jump to the next or previous line that has the same level or a lower " level of indentation than the current line. " " exclusive (bool): true: Motion is exclusive " false: Motion is inclusive " fwd (bool): true: Go to next line " false: Go to previous line " lowerlevel (bool): true: Go to line with lower indentation level " false: Go to line with the same indentation level " skipblanks (bool): true: Skip blank lines " false: Don't skip blank lines function! NextIndent(exclusive, fwd, lowerlevel, skipblanks) let line = line('.') let column = col('.') let lastline = line('$') let indent = indent(line) let stepvalue = a:fwd ? 1 : -1 while (line > 0 && line <= lastline) let line = line + stepvalue if ( a:lowerlevel == 0 && indent(line) == indent || \ a:lowerlevel == 1 && indent(line) < indent || \ a:lowerlevel == -1 && indent(line) > indent) if (! a:skipblanks || strlen(getline(line)) > 0) if (a:exclusive) let line = line - stepvalue endif exe line exe 'normal ' (column+1) . '|' return endif endif endwhile endfunction " moving back and forth between lines of same or lower indentation should be sane nnoremap [l :call NextIndent(0, 0, 0, 1) nnoremap ]l :call NextIndent(0, 1, 0, 1) nnoremap [L :call NextIndent(0, 0, 1, 1) nnoremap ]L :call NextIndent(0, 1, 1, 1) nnoremap [ :call NextIndent(0, 0, -1, 1) nnoremap ] :call NextIndent(0, 1, -1, 1) vnoremap [l :call NextIndent(0, 0, 0, 1)m'gv'' vnoremap ]l :call NextIndent(0, 1, 0, 1)m'gv'' vnoremap [L :call NextIndent(0, 0, 1, 1)m'gv'' vnoremap ]L :call NextIndent(0, 1, 1, 1)m'gv'' onoremap [l :call NextIndent(0, 0, 0, 1) onoremap ]l :call NextIndent(0, 1, 0, 1) onoremap [L :call NextIndent(1, 0, 1, 1) onoremap ]L :call NextIndent(1, 1, 1, 1) " run make with leader,m nnoremap m :call RunMake() " NERDTree bindings " show file manager in current directory nnoremap :NERDTreeToggle " show file manager in git repo root nnoremap n :call NERDProjectViewer() " focus the current file in NERDTree nnoremap gn :NERDTreeFind " don't kill vim " REBIND nnoremap K nnoremap " quick paragraph formatting vmap Q gq nmap Q gqap " launch fzf for the current git repo nnoremap :GitFiles " launch fzf for files in the current directory nnoremap :Files " launch fzf for files modified or not in git nnoremap :GFiles? " launch fzf for open buffers (files) nnoremap :Buffers " launch fzf for open buffers (files) nnoremap l :Buffers if has("nvim") au FileType fzf tnoremap endif " switch to previous buffer nnoremap h :b# " use leader j and k to switch buffers as well nnoremap k :bnext nnoremap j :bprevious " window/pane navigation nnoremap :TmuxNavigateLeft nnoremap :TmuxNavigateDown nnoremap :TmuxNavigateUp nnoremap :TmuxNavigateRight if has('nvim') nnoremap r :source $vimdir/init.vim else nnoremap r :source $HOME/.vimrc endif " change buffers with leader,tab nnoremap :bnext nnoremap :bprevious " fast word change nnoremap c ciw nnoremap C ciW " fast splits nnoremap s :split nnoremap v :vsplit " fast split closing nnoremap q q " fast force quit nnoremap Q :qall! " clear search higlight nnoremap / :let @/ = "": " remap jk/jj and its variants to escape inoremap jj inoremap Jj inoremap Jj inoremap JJ inoremap jk inoremap Jk inoremap jK inoremap JK " use hjkl-movement between rows when soft wrapping: nnoremap j gj nnoremap k gk vnoremap j gj vnoremap k gk " camel case motions map ,w CamelCaseMotion_w map ,b CamelCaseMotion_b map ,e CamelCaseMotion_e map ,ge CamelCaseMotion_ge " inner _ objects omap ib CamelCaseMotion_ib xmap ib CamelCaseMotion_ib omap ie CamelCaseMotion_ie xmap ie CamelCaseMotion_ie " remove trailing whitespace map mw:%s/\s\+$//:let @/ = ""'w " close buffer with leader-w nnoremap w :bd " toggle spell checking: map :setlocal spell! " open urls, files, etc. example: http://google.com: noremap o :!xdg-open " insert newline " NOTE: doesn't work in terminals? " noremap i " noremap i " prevent wildmenu map q: :q noremap qqq: q: " sane n/N behavior nnoremap n 'Nn'[v:searchforward] nnoremap N 'nN'[v:searchforward] " better command history navigation cnoremap cnoremap " keep selection after indenting visual selection xnoremap < >gv " distraction-free mode nnoremap df :DistractionFreeMode " recalc syntax highlighting nnoremap gs :syntax sync fromstart " lsp bindings " coc " open coc config nnoremap c :CocConfig " smart jumps nmap gd (coc-definition) nmap gy (coc-type-definition) nmap gi (coc-implementation) nmap gr (coc-references) nmap g[ (coc-diagnostic-prev) nmap g] (coc-diagnostic-next) nmap ac (coc-codeaction) nmap qf (coc-fix-current) nmap f (coc-format) vmap f (coc-format-selected) " ale " go to definitions " nnoremap gd :ALEGoToDefinition " nnoremap gh :ALEGoToDefinitionInSplit " nnoremap gv :ALEGoToDefinitionInVSplit " misc plugins nmap aa :%ArrangeColumn!