- 0 Talk
-
Window zooming convenience
created October 11, 2001 · complexity basic · author Salman Halim · version 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
wincmd =
unlet g:windowMax
else
augroup maxCurrWin
" au BufEnter * wincmd _ | wincmd |
"
" only max it vertically
au! WinEnter * wincmd _
augroup END
do maxCurrWin WinEnter
let g:windowMax=1
endif
endfunction
nnoremap <Leader>max :call ToggleMaxWins()<CR>
Comments
Edit
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.
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.
For info on <Leader> see :help mapleader.
TO DO
Merge below content.
Is this a different way of achieving Tony M.'s "Rolodex Vim" feature he mentions every now and then?
- I think so. The feature is explained in detail in a comment under Going to the nth-from-last window. In a nutshell:
- Zoom in (permanently)
- :set noequalalways winminheight=0 winheight=9999 helpheight=9999
- Zoom out (permanently)
- :set winheight=1 helpheight& equalalways | wincmd =
- Zoom in (temporarily)
- <Ctrl-_>
- Zoom out (temporarily)
- <Ctrl-=>
- The above works even in Vim versions without the +autocmd feature. Of course, +windows is still required, but "Small" builds normally have -autocmd +windows so the hypothesis is not unrealistic. --Tonymec 22:54, September 22, 2009 (UTC)
Moved from Going_to_the_nth-from-last_window Tony: I do not think you have mentioned your "Rolodex style" window layout on the wiki (although I've seen you refer to it at vim_use). Would you be able to add a couple of paragraphs to this tip because it's an interesting idea and it would be a good illustration of the point of the tip? Or if you prefer, reply with a description and I'll incorporate it. BTW it is mentioned in the last comment at Window zooming convenience. JohnBeckett 07:30, 5 August 2009 (UTC)
I'm not sure I've made a tip for it, though I have indeed mentioned it time and again on the vim groups, even on vim@ since before 7.0 came around. I called it "the poor man's tabs" at first, though "Rolodex" is more descriptive, once someone figuratively threw the latter name on the wall, it stuck. The idea is obvious once you have seen it:
:set noequalalways winminheight=0 winheight=9999 helpheight=9999
- 'noequalalways' makes sure Vim doesn't try to make all windows equal.
- 'winminheight' set to 0 means non-current windows may collapse to a status line and nothing else (thus sparing screen real estate)
- 'winheight' at 9999 swells the current window to maximum height, squashing all non-current windows
- 'helpheight' does the same when in a help window.
The result is that the current window opens full-height, pushing all other windows above and below it to just a status line each. To see what it means, figure a Rolodex phone directory, like we (or our fathers' secretaries) used to have before personal computers came around. The current card is open full-size, with the borders of the previous cards visible above it and those of the following cards below it. You can even push the similarity further: mouse-clicking any status line opens that "Rolodex page" in Vim, like holding one index letter on the top or bottom side of the Rolodex® allowed to open that directory card in the good old paper-and-ink times of a generation ago. Of course the "Vim Rolodex pages" can also be turned up and down one-by-one with ^Ww and ^WW etc.
See:
--Tonymec 21:49, 5 August 2009 (UTC)
Great tip—I always edit in this mode. Problem is, the quickfix window gets shrunk to nothing. Does anyone have any idea how to set the quickfix window (:help :cw) to a minimum of 12 lines (say) while in rolodex mode?
- Try the following (untested) after opening the quickfix window (and with it being current):
:setlocal winfixheight=12
(see :help 'winfixheight') — Tonymec 05:25, September 25, 2010 (UTC)- 'winfixheight' is a boolean option. You want something like :resize 12 | setlocal winfixheight. --Fritzophrenic 14:38, September 27, 2010 (UTC)
- But help says that winfixheight is set in a quickfix window, and that it will be ignored when running out of room. So something more would be needed. JohnBeckett 11:15, September 28, 2010 (UTC)
- 'winfixheight' is a boolean option. You want something like :resize 12 | setlocal winfixheight. --Fritzophrenic 14:38, September 27, 2010 (UTC)