Reputation: 7109
I used to use ZoomWin: https://github.com/vim-scripts/ZoomWin for toggle between one and multiple windows in Vim. But this plugin has one big issue. When I`m trying to restore multiple windows(vertical split) there is about 2-4 sec delay.
Do you know how to avoid that lag? Or maybe is better solution for that.
Version 25 solved problem: https://github.com/regedarek/ZoomWin
Upvotes: 66
Views: 22023
Reputation: 2065
I wrote one really similar to BenC's version (had not seen it before so it was giggle-worthy to see that one)
I think the only difference is the autocmd that restores the layout if you want to move to another window in the same tab, so it creates an "auto-unzoom" effect:
function! ToggleZoom(toggle)
if exists("t:restore_zoom") && (t:restore_zoom.win != winnr() || a:toggle == v:true)
exec t:restore_zoom.cmd
unlet t:restore_zoom
elseif a:toggle
let t:restore_zoom = { 'win': winnr(), 'cmd': winrestcmd() }
vert resize | resize
endi
endfunction
nnoremap <silent> <Leader>+ :call ToggleZoom(v:true)<CR>
augroup restorezoom
au WinEnter * silent! :call ToggleZoom(v:false)
augroup END
Upvotes: 2
Reputation: 4967
I have another method that I've used for years; allows me to 'zoom' the current buffer to a new tab, and then quickly close it again, so that I can go back to my original multi-window layout:
" "Zoom" a split window into a tab and/or close it
nmap <Leader>,zo :tabnew %<CR>
nmap <Leader>,zc :tabclose<CR>
Upvotes: 17
Reputation: 141
Another simple way is :tab split
. The upside is that it doesn't change the layout of the current tab. The downside is that it requires Vim 7.0 or above for tab support.
nnoremap <leader>t :call TabToggle()<cr>
function! TabToggle()
if tabpagewinnr(tabpagenr(), '$') > 1
" Zoom in when this tab has more than one window
tab split
elseif tabpagenr('$') > 1
" Zoom out when this tab is not the last tab
if tabpagenr() < tabpagenr('$')
tabclose
tabprevious
else
tabclose
endif
endif
endfunction
Upvotes: 14
Reputation: 4493
I try to use vim without any plugins as I don't want to rely on them when I work on another system. Coming upon this same issue now, I can propose some 'better ways' (alternative ways) as requested by the OP:
c-w-|
to have window take over (if using vsplits). c-w-=
to restore. c-w-_
for horizontal splitstmux
if available and run multiple instances of vim, c-b-z
to switch between fullscreen for the current paneI have listed these in order of my perceived practicality. Experience will of course be better with a dedicated plugin, but that is not always an option.
Upvotes: 105
Reputation: 8976
A simple alternative (which may be enough depending on what you need):
" Zoom / Restore window.
function! s:ZoomToggle() abort
if exists('t:zoomed') && t:zoomed
execute t:zoom_winrestcmd
let t:zoomed = 0
else
let t:zoom_winrestcmd = winrestcmd()
resize
vertical resize
let t:zoomed = 1
endif
endfunction
command! ZoomToggle call s:ZoomToggle()
nnoremap <silent> <C-A> :ZoomToggle<CR>
Upvotes: 56
Reputation: 172688
The ZoomWin version 24 introduced saving of window-local variables. When I've tried it out, I found the performance unacceptable, probably because of the various other plugins that I have installed and which install various event handlers.
I've reported my issues to the plugin author and he replied that
v25a of ZoomWin has the g:zoomwin_localoptlist and noautocmd stuff.
So, either try reverting to version 23 (which I did), or try out the latest version with the mentioned setting turned off from http://drchip.org/astronaut/vim/index.html#ZOOMWIN
Upvotes: 13