sponsor Vim development Vim logo Vim Book Ad

basic Tip #132: window zooming convenience

 tip karma   Rating 15/10, Viewed by 1560 

created:   October 11, 2001 13:38      complexity:   basic
author:   Salman Halim      as of Vim:   6.0

i frequently have multiple windows open in vim -- this reduces the number of lines each window displays -- i almost always have my windows either all the same size or the current one as big as possible.

the following function can be toggled on or off by typing <Leader>max (i can do this quite quickly); just change the mapping at the bottom to something else if you prefer.

this causes the current window to be as big as possible (moving into another window causes that one to become big) and all the others get very small.  i actually use this ALL the time.  turning it off (by typing the hotkey sequence again) will cause all windows to have the same height.

"toggles whether or not the current window is automatically zoomed
function! ToggleMaxWins ()
  if exists ('g:windowMax')
    au! maxCurrWin
    exe "normal \<c-w>="
    unlet g:windowMax
  else
    augroup maxCurrWin
    " au BufEnter * exe "normal \<c-w>_\<c-w>\<bar>"
    "
    " only max it vertically
    au! BufEnter * exe "normal \<c-w>_"
    augroup END
    do maxCurrWin BufEnter
    let g:windowMax=1
  endif
endfunction
map <Leader>max :call ToggleMaxWins ()<CR>

 rate this tip  Life Changing Helpful Unfulfilling 

<<Scroll alternate window | Windo and Bufdo >>

Additional Notes

[email protected], October 12, 2001 5:27
Note that the essential Vim commands are <c-_> which maximizes the current
window by making all of the other windows 1-line high.  And <c-=> which makes
all window sizes the same.

The script just makes it easier to toggle.
[email protected], October 12, 2001 6:21
i just like not having to explicitly maximize the current window every time.  i never said it couldn't be done by hand at will.  i just frequently have four or five source windows open and it's easier to just have them become bigger automatically.
[email protected], October 13, 2001 12:42
i noticed that the bufenter commands only happen when moving from one buffer to another (in a different window) -- if you have two windows with the same buffer, the bufenter commands don't get triggered and the zooming doesn't happen.  to make it happen for all WINDOWS, change all the above BufEnter occurrences to WinEnter.
[email protected], October 14, 2001 14:20
what is "<Leader>"?
[email protected], October 14, 2001 19:21
for info on <leader> see
:help mapleader
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
    stats
Sponsored by Web Concept Group Inc. SourceForge.net Logo