63

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
tomekfranek
  • 6,852
  • 8
  • 45
  • 80

7 Answers7

103

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.

ljs.dev
  • 4,449
  • 3
  • 47
  • 80
56

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>
BenC
  • 8,729
  • 3
  • 49
  • 68
15

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>
JESii
  • 4,678
  • 2
  • 39
  • 44
13

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

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • 5
    Thank you! Version 25 Works excellent. I just pushed newest version to my Github account. https://github.com/regedarek/ZoomWin – tomekfranek Nov 02 '12 at 12:40
  • Yes, I've just tried with v25d, and, though not as fast as v23, the delay on my old laptop is ~200 ms, which I think I can live with. – Ingo Karkat Nov 02 '12 at 20:52
  • Is the original author not maintaining it anymore? Do you have his permission? – Steven Lu Jun 04 '13 at 03:21
12

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
Hanhong Xue
  • 121
  • 1
  • 2
  • I like this one! I wrote my own almost exactly like BenC's, but attempted before to do something with tabe % and this is what I was after at that point. Good alternative. – ata Mar 11 '20 at 16:13
  • This solution has the advantage not scrolling your terminal splits all the way to the bottom when you zoom in on your code and then zoom out (which is what happens to me with C-w+_ and C-w+= – Yordan Grigorov Dec 13 '20 at 15:16
  • For those that just this without the remap, one way is to `Ctrl+w s` to copy the split into a new buffer, then `Ctrl+w T` to break it out into a new tab. When you're done, just close the new tab and the original layout is restored. – user1717828 Jun 16 '21 at 12:31
2

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
ata
  • 2,045
  • 1
  • 14
  • 19
1

I replaced ZoomWin with the excellent Zen Mode.

mxgrn
  • 1,733
  • 16
  • 20