" common typo fixes command! WQ wq command! Wq wq command! Wqa wqa command! W w command! Q q " best leader let mapleader = "\" if has('nvim') " terminal mappings " open a terminal split at 80 columns nnoremap :vsplit term://bash nnoremap :split term://bash " tnoremap :call TerminalSplit() " close the terminal tnoremap :q! " moving between terminal splits tnoremap :TmuxNavigateLeft tnoremap :TmuxNavigateDown tnoremap :TmuxNavigateUp tnoremap :TmuxNavigateRight endif " enter insert mode when entering a terminal buffer augroup InsertModeOnBlankTerminal autocmd BufWinEnter,WinEnter term://* startinsert augroup END " 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() " show project viewer with leader,n or C-n nnoremap :call NERDProjectViewer() nnoremap n :call NERDProjectViewer() " 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 " switch to previous buffer nnoremap h :b# " use leader j and k to switch buffers as well nnoremap k :bnext nnoremap j :bprevious nnoremap :bnext nnoremap :bprevious " change buffers with leader,tab nnoremap :bnext nnoremap :bprevious " fast word change nnoremap c ciw nnoremap C ciW " 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