Tip #199: maximize window and return to previous split structure
tip karma |
Rating 21/9, Viewed by 2926
|
Read and edit this tip on the
Vim tip wiki.
The wiki may have a more recent version of this tip.
created: |
|
January 15, 2002 16:32 |
|
complexity: |
|
intermediate |
author: |
|
scotch2 |
|
as of Vim: |
|
6.0 |
Say you have layed out a complex window split structure, and want to temporarily open 1 window with max dimensions, but don't want to lose your split structure. The following function and mappings let you toggle between the split windows and on window maximized. The mappings prevent the default behavior of calling :only and losing your finely tuned splits.
Put this bit in your vimrc file, change mappings if you don't want to override the defaults:
nnoremap <C-W>O :call MaximizeToggle ()<CR>
nnoremap <C-W>o :call MaximizeToggle ()<CR>
nnoremap <C-W><C-O> :call MaximizeToggle ()<CR>
function! MaximizeToggle()
if exists("s:maximize_session")
source s:maximize_session
call delete(s:maximize_session)
unlet s:maximize_session
let &hidden;=s:maximize_hidden_save
unlet s:maximize_hidden_save
else
let s:maximize_hidden_save = &hidden;
let s:maximize_session = tempname()
set hidden
mksession! s:maximize_session
only
endif
endfunction
<< Pasting code with syntax coloring in emails |
Bouncing Parentheses (during insertion) >>
Additional Notes
[email protected],
January 16, 2002 17:34
|
There is a bug in the function such that the session file used is "s:maximize_session" in the current directory rather than the temp file created with tempname (). Replace the function with this:
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
else
let s:maximize_hidden_save = &hidden;
let s:maximize_session = tempname()
set hidden
exec "mksession! " . s:maximize_session
only
endif
endfunction
|
[email protected],
April 24, 2003 8:25
|
perhalf you can leave that complex window alone and open another gvim session...
|
Anonymous,
October 11, 2006 21:19
|
This was something that I wanted for a while as well. In vim 7 there is a nice solution using tabs.
:tabedit % will open the current buffer in a new tab
:tabclose when finished and return to your finely tuned set of splits.
I mapped them to the following sequences for quick access.
nmap t% :tabedit %<CR>
nmap td :tabclose<CR>
I'm now far happier when editing several files at once.
|
|