How to toggle between all vertical and all horizontal window layout
From Vim Tips Wiki
Tip 862 • Previous Tip • Next Tip
Created: January 25, 2005 Complexity: intermediate Author: Charles E. Campbell, Jr. Minimum version: 6.0 Karma: 81/44 Imported from: Tip#862
Suppose you have three windows in a "horizontal list", like this:
W|W|W
Entering the command:
:windo wincmd K
will change the windows to a "vertical list", like this:
W W W
Starting with a "vertical list", entering the command:
:windo wincmd H
will change the windows to a "horizontal list".
[edit] Comments
Very useful, I already added it as a command to my vimrc:
command -nargs=0 MyArrangeWindowsVertically :windo wincmd K cnoremap <unique> myawv MyArrangeWindowsVertically command -nargs=0 MyArrangeWindowsHorizontally :windo wincmd H cnoremap <unique> myawh MyArrangeWindowsHorizontally
I should mention that there's a shorter pair of commands that almost does the same thing:
:sba :vert sba
The difference is that these two commands will open a window for all buffers on the buffer list, not just re-arrange the display of current windows. Try :ls! to see the buffer list.
The following two maps help with window resizing:
nmap + <C-W>+ nmap - <C-W>-
I've written a small plugin (twl.vim) that implements :TWL (toggle window layout) which detects which type of window layout you currently have (vertical vs horizontal) and applies the correct command to toggle the layout. Its at http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs (see "Toggle Window Layout").
