Index syndication
comment syndication

Vim Split tips

May 22, 2008 at 10:16 · Filed under apps, unix

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
    " Map multi window keys
    set wmw=0
    " CTRL-H move to left window
    nmap <c -h> </c><c -w>h</c><c -w><bar>
    " CTRL-L move to right window
    nmap <c -l> </c><c -w>l</c><c -w><bar>
  • 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
    " Map \zz to lock scroll to middle of window
    map <leader>zz :let &scrolloff=999-&scrolloff<cr>
  • 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 ()<cr>
    nnoremap <c -W>o :call MaximizeToggle ()<cr>
    nnoremap <c -W></c><c -O> :call MaximizeToggle ()<cr>
    function! MaximizeToggle()
      if exists("s:maximize_session")
        exec "source " . s:maximize_session
        call delete(s:maximize_session)
        unlet s:maximize_session
        let &hidden=s:maximize_hidden_save
        unlet s:maximize_hidden_save
        let s:maximize_hidden_save = &hidden
        let s:maximize_session = tempname()
        set hidden
        exec "mksession! " . s:maximize_session

Yogi said,

December 17, 2009 @ 23:46

I copied the above code and I got an “endfunction error”. I changed the last line to read as “endfunction” (all small) and the error did not appear.

Thanks for the code

lantrix said,

December 22, 2009 @ 00:56

Thanks for that. I checked my .vimrc and had it all in lowercase as well. I’ve fixed the post.

RSS feed for comments on this post · TrackBack URI

Leave a Comment