Is better way to zoom windows in Vim than ZoomWin?

VimZoomingVim Plugin

Vim Problem Overview


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

Vim Solutions


Solution 1 - Vim

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 splits
  • close the other window(s), thereby making current one fullscreen. Split and re-open from buffer to restore
  • use tmux if available and run multiple instances of vim, c-b-z to switch between fullscreen for the current pane

I 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.

Solution 2 - Vim

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>

Solution 3 - Vim

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

Solution 4 - Vim

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

Solution 5 - Vim

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>

Solution 6 - Vim

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontomekfranekView Question on Stackoverflow
Solution 1 - Vimljs.devView Answer on Stackoverflow
Solution 2 - VimBenCView Answer on Stackoverflow
Solution 3 - VimIngo KarkatView Answer on Stackoverflow
Solution 4 - VimHanhong XueView Answer on Stackoverflow
Solution 5 - VimJESiiView Answer on Stackoverflow
Solution 6 - VimataView Answer on Stackoverflow