Skip to main content

Vim Split tips

I use vim a lot of the time, mostly with splits and diffs, so the following key mappings and functions really helped me with managing the split windows. Maybe they will help you too. (Thanks to the Vim tips wiki for these).

  • If you use vertical splits, this will help move left and right across the split. Put in your ~/.vimrc
    <br /> " Map multi window keys<br /> set wmw=0<br /> " CTRL-H move to left window<br /> nmap <c -h> </c><c -w>h</c><c -w><bar><br /> " CTRL-L move to right window<br /> nmap <c -l> </c><c -w>l</c><c -w><bar><br /> </bar></c></bar></c>
  • When scrolling up and down a window, you can use zz to jump the current line to the middle of the window. If you want this on always ala Scroll locking, then you can use this function. It is a toggle option. use \zz to toggle it. Put in your ~/.vimrc
    <br /> " Map \zz to lock scroll to middle of window<br /> map <leader>zz :let &scrolloff=999-&scrolloff<cr><br /> </cr></leader>
  • In a window split (of any sort) if you want to maximise to the current window, this will do it for you. When you press CTRL-W then o it will maximise the current view, then when pressed again will return your split arrangement! Put in your ~/.vimrc
    ` " Max/unmax splits nnoremap <c -W>O :call MaximizeToggle () nnoremap <c -W>o :call MaximizeToggle () nnoremap <c -W><c -O> :call MaximizeToggle ()