" define the leader to be explicitly \ char let mapleader='\' " use XX as escape inoremap XX cnoremap XX onoremap XX vnoremap XX gV nnoremap XX :noh if has('nvim') tnoremap XX endif " ================================ " vimrc handling " ================================ " load .vimrc - r if !has('nvim') noremap r :sp ~/vimrc_ " activating changes (after save) - R nmap R :source $MYVIMRC:filetype detect:exec ":echo 'vimrc reloaded'" else noremap r :sp ~/.config/nvim/init_ " activating changes (after save) - R nmap R :source $MYVIMRC:filetype detect:exec ":echo 'init.vim reloaded'" endif if &term[:4] ==? 'xterm' || &term[:5] ==? 'screen' || &term[:3] ==? 'rxvt' inoremap OC endif " Fast saving noremap w :w! " ================================================== " Window navigation " ================================================== " control + vim direction key to navigate windows noremap j noremap k noremap h noremap l " control + arrow key to navigate windows noremap j noremap k noremap h noremap l " ================================================== " Splits handling " ================================================== " Make these all work in insert mode inoremap " - and + to resize horizontal splits noremap - - noremap + + " alt-< or alt-> for vertical splits noremap > noremap < " F2 close current split (window) noremap :close " ================================================ " Buffers " ================================================ " delete current buffer noremap d :bd " Deleter buffer, keep the split (switch to prev buf, delete now prev buf) noremap D :b#bd# " buffer navigation nnoremap :bn " toggle between open buffers go to next buffer nnoremap :bp " toggle between open buffers go to prev buffer nnoremap bfn :bn " toggle between open buffers go to next buffer nnoremap bfp :bp " toggle between open buffers go to prev buffer nnoremap x :bn\|bd # " delete next buffer " ================================================== " Clean all end of line whitespace with S " ================================================== nnoremap S :let _s=@/:%s/\s\+$//e:let @/=_s:nohl " ================================================== " F5 toggles hlsearch on/off, show current value " " Probably would be better to use unimapaired's coh " ================================================== noremap :set hlsearch! hlsearch? " Search mappings: These will make it so that going to the next one in a " search will center on the line it's found in. nnoremap n nzzzv nnoremap N Nzzzv " clear last search register norema srln :let @/='' " center line when moving up and down half a screen noremap zz noremap zz if ! has('nvim') " ================================================== " Fix meta key in terminal " fix meta-keys which generate a .. z " ================================================== let c='a' while c <= 'z' exec 'set =\e'.c exec 'imap \e'.c.' ' let c = nr2char(1+char2nr(c)) endw endif " treat long lines as break lines (when moving around in them) noremap j gj noremap k gk " Move a line of text using ALT+[jk] or Comamnd+[jk] on mac nnoremap mz:m+`z nnoremap mz:m-2`z vnoremap :m'>+`mzgv`yo`z vnoremap :m'<-2`>my` nnoremap vnoremap vnoremap endif " swap content " swap current char with the next nnoremap gc xph " swap current chat with the prev nnoremap gC Xph " swap current word with the prev nnoremap gl "_yiw?\w\+\_W\+\%#:s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/:nohlsearch " swap current word with the next nnoremap gr "_yiw:s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1//\w\+\_W\+:nohlsearch " swap current paragraph with the next nnoremap g{ {dap}p{ " swap current paragraph with the prev nnoremap g} }dap{p} " ==================================================== " spell settings " ==================================================== noremap SPT :set spell! nnoremap SPT :set spell! vnoremap SPT :set spell! " move to next spelling word noremap sn ]s " move to prev spelling word noremap sp [s " add word under cursor noremap sa zg " suggestion window noremap s? z= " ======================================================= " VCS/Git Merge stuff " ======================================================= " Find merge conflict markers noremap vcsfc /\v^[<\|=>]{7}( .*\|$) " ======================================================= " Code folding options " ======================================================= nnoremap f0 :set foldlevel=0 nnoremap f1 :set foldlevel=1 nnoremap f2 :set foldlevel=2 nnoremap f3 :set foldlevel=3 nnoremap f4 :set foldlevel=4 nnoremap f5 :set foldlevel=5 nnoremap f6 :set foldlevel=6 nnoremap f7 :set foldlevel=7 nnoremap f8 :set foldlevel=8 nnoremap f9 :set foldlevel=9 " ======================================================= " Miscprevious " ======================================================= " toggle paste " nnoremap :set paste! " noremap :set paste! " paste while keeping the current indent nnoremap p p`[v`]= nnoremap P P`[v`]= "remove the Windows ^M - when the encodings gets messed up noremap m mmHmt:%s///ge'tzt'm " manage current active buffer " toggle between last two buffers nnoremap b :redraw! " go to previous buffer nnoremap p :bprevious:redraw! " go to next buffer nnoremap n :bnext:redraw! " Allow to copy/paste between VIM instances "copy the current visual selection to ~/.vbuf vnoremap y :w! ~/tmp/.vbuf "copy the current line to the buffer file if no visual selection nnoremap y :.w! ~/tmp/.vbuf "paste the contents of the buffer file nnoremap cf :r ~/tmp/.vbuf " Yank from the cursor to the end of the line, to be consistent with C and D. nnoremap Y y$ " visual reselect of just yanked nnoremap gp `[v`] if has('macunix') " pbcopy for OSX copy/paste vnoremap :!pbcopy vnoremap :w !pbcopy endif "" Map ff to display all lines with keyword under cursor " and ask which one to jump to nnoremap ff [I:let nr = input('Which one: ')exe 'normal ' . nr .'[\t' " tabular resize on insert mode " inoremap :call align()a " Error window (a.k.a. quick fix window) " augroup QuickFix " autocmd BufReadPost,BufWinEnter quickfix nnoremap erf :cfirstzz:set cul " autocmd BufReadPost,BufWinEnter quickfix nnoremap erl :clastzz:set cul " autocmd BufReadPost,BufWinEnter quickfix nnoremap ern :cnextzz:set cul " autocmd BufReadPost,BufWinEnter quickfix nnoremap erp :cpreviouszz:set cul " autocmd BufReadPost,BufWinEnter quickfix nnoremap erc :cclosezz:set cul " autocmd BufReadPost,BufWinEnter quickfix nnoremap err :crewindzz:set cul " autocmd BufReadPost,BufWinEnter quickfix nnoremap erw :cwindow " autocmd BufReadPost,BufWinEnter quickfix nnoremap erlw :lwindow< " autocmd BufReadPost,BufWinEnter quickfix nnoremap erln :lnextzz:set cul " autocmd BufReadPost,BufWinEnter quickfix nnoremap erlp :lpreviouszz:set cul " autocmd BufReadPost,BufWinEnter quickfix nnoremap erlf :lfirstzz:set cul " autocmd BufReadPost,BufWinEnter quickfix nnoremap erll :llastzz:set cul " autocmd BufReadPost,BufWinEnter quickfix nnoremap erlc :lclosezz:set cul " autocmd BufReadPost,BufWinEnter quickfix nnoremap erlr :lrewindzz:set cul " augroup END nnoremap q :call CloseQuickFix()zz:set cul " Close all windows except the active one nnoremap q :only " Print full path noremap :echo expand("%:p") " Exit diff mode noremap :windo diffoff " Toggle view of hidden chars noremap hc :set list! inoremap hc :set list!a " Toggle word wrap noremap wrp :set wrap! inoremap wrp :set wrap!a " sort numbers in paragraph noremap srt {V}k:!sort vnoremap srt {V}k:!sort "For navigating tabs like gui applications nnoremap gt nnoremap gT nnoremap :tabnew nnoremap :tabnew noremap :retab inoremap :retabi vnoremap :retab if has('nvim') noremap T :terminal endif " add support for toggle relative numbers noremap rel :set rnu! inoremap rel :set rnu!a " Move back and forth through commits while staying on the same line nnoremap :call GlogForward() nnoremap :call GlogBackward() "make enter break and do newlines nnoremap i== " nnoremap Oj nnoremap j i== " Toggle cursor indicators noremap curc :set cursorcolumn! inoremap curc :set cursorcolumn! noremap curr :set cursorline! inoremap curr :set cursorline! " indent the last changed text nnoremap g= gV= " Surround word nnoremap sr" :normal ysiw" nnoremap sr' :normal ysiw' nnoremap sr` :normal ysiw` nnoremap sr( :normal bce()P nnoremap sr) :normal ce()P nnoremap sr[ :normal bce[]P nnoremap sr] :normal ce[]P nnoremap sr{ :normal bce{}P nnoremap sr} :normal ce{}P " Macros nnoremap Q q nnoremap M @q vnoremap M :norm @q " Remove macro key nnoremap q " viewport " Adjust viewports to the same size nnoremap = = " find files nnoremap ,f :find nnoremap ,s :sfind nnoremap ,v :vert sfind nnoremap ,t :tabfind