Is better way to zoom windows in Vim than ZoomWin?
Asked Answered
F

7

65

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

Fuchs answered 2/11, 2012 at 11:33 Comment(2)
The lag makes zoomwin a no-go for me.Majordomo
BenC answer below has the perf. needed.Majordomo
D
3

I replaced ZoomWin with the excellent Zen Mode.

Dominicadominical answered 27/1, 2023 at 0:29 Comment(0)
B
104

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.

Bayly answered 21/5, 2015 at 0:26 Comment(1)
Nice, but C-w-= does not restore but splits in the middle (whereas the original split might have been different).Retene
R
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>
Rozellarozelle answered 24/10, 2014 at 15:22 Comment(10)
This is pretty good actually! Note that you might need to remap <C-A> to something else if you're already using this combination with tmux =)Ticino
@Abdo: indeed, I mapped it to <Leader><Leader> since I use <C-A> for tmux ;-)Rozellarozelle
Haha, nice! :-) I mapped it to <Leader>E since I have cmd shift e as my shortcut to expand windows in my OSX =)Ticino
A corresponding plugin using the same technique: github.com/szw/vim-maximizerSphenic
Great solution. Works like a charm.Illtimed
Your amazing! .Clemmieclemmons
Thanks a ton ! Your script does exactly what i wanted & along with a mapping of <leader>z => It makes it similar to the zoom in tmux !Roundsman
Ideal. Thank you!Majordomo
this comment should be accepted answer, it works like a charm.Verbal
Using this mapping allows you to use the same familiar CTRL-W vim reflex, but with a Z at the end (akin to tmux) (CTRL-W-Z): nnoremap <silent> <C-W><C-Z> :ZoomToggle<CR>Astatine
A
16

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>
Anticlockwise answered 7/12, 2018 at 13:50 Comment(1)
great solution.Acedia
S
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

Scrannel answered 2/11, 2012 at 12:5 Comment(3)
Thank you! Version 25 Works excellent. I just pushed newest version to my Github account. github.com/regedarek/ZoomWinFuchs
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.Scrannel
Is the original author not maintaining it anymore? Do you have his permission?Waldron
F
13

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
Fromenty answered 18/9, 2016 at 20:34 Comment(3)
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.Pandit
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+=Eada
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.Blur
D
3

I replaced ZoomWin with the excellent Zen Mode.

Dominicadominical answered 27/1, 2023 at 0:29 Comment(0)
P
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
Pandit answered 11/3, 2020 at 16:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.