" bindings " 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 h " tnoremap j " tnoremap k " tnoremap l 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 && indent(line) == indent || \ a:lowerlevel && indent(line) < indent) if (! a:skipblanks || strlen(getline(line)) > 0) if (a:exclusive) let line = line - stepvalue endif exe line exe 'normal ' column . '|' return endif endif endwhile endfunction " Moving back and forth between lines of same or lower indentation. 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) 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() " change buffers with leader,tab nnoremap :bnext nnoremap :bprevious " don't kill vim nnoremap K nnoremap " nerdtree nnoremap :NERDTree " run macro across visually selected lines xnoremap @ :call ExecuteMacroOverVisualRange() function! ExecuteMacroOverVisualRange() echo '@'.getcmdline() execute ":'<,'>normal @".nr2char(getchar()) endfunction " 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 " fast word change nnoremap c ciw nnoremap C ciW " bash-like deletion inoremap inoremap " 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 movements 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 " a _ objects " omap aw CamelCaseMotion_aw " xmap aw CamelCaseMotion_aw omap ab CamelCaseMotion_ab xmap ab CamelCaseMotion_ab omap ae CamelCaseMotion_ae xmap ae CamelCaseMotion_ae " 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 " run `make run` nnoremap R :ProjectRootExe !make run " insert newline " doesn't work in terminals? " noremap i " noremap i " keep that dumb window from popping up (wild something or another) 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 nmap ga xmap ga nnoremap df :DistractionFreeMode