Skip to content

Instantly share code, notes, and snippets.

@3coma3
Last active March 26, 2020 21:25
Show Gist options
  • Save 3coma3/a0950bc79055fb9ded6363c554e162d0 to your computer and use it in GitHub Desktop.
Save 3coma3/a0950bc79055fb9ded6363c554e162d0 to your computer and use it in GitHub Desktop.
add a map to vim to toogle zooming a split to max width/height - moving out to a same-tab split or closing the zoomed split also restores the window layout
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
endif
endfunction
augroup restorezoom
au WinEnter * silent! :call ToggleZoom(v:false)
augroup END
nnoremap <silent> <C-\> :call ToggleZoom(v:true)<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment