I open multiple windows when using vim. Sometimes I want to only focus on one window for readability by using :only command or Ctrlw-W o shortcut. How do I get back to the multi split windows?
- 13
- 2
3 Answers
My solution to this problem is a mapping that opens the current window in its
own tab. Then I can just do :q to close it and return to the previous tab
(where all the windows are unchanged):
" open current split in own tab (like zoom in tmux) and keep cursor pos
nnoremap <LEADER>z mx:tabedit %<CR>g`x
- 1,111
- 4
- 15
My solution to this problem is to use the vim-aximizer plugin: https://github.com/szw/vim-maximizer
It offers a shortcut Ctrl-w m to toggle between the window maximized and original window layout.
- 16,336
- 3
- 18
- 37
:only closes all other windows in the current tab. And once a window has been closed it's gone. So there'll be no way "to get'em back" except to open the same number of windows while assigning same buffers. Kind of what a Vim session does.
So I prefer to maximize current window size while keeping all other open. This can be achieved by setting :h 'winwidth' and :h 'winheight' options. An example code:
" :Zoom
" toggle current window maximized
command! -bar Zoom
\ if winnr('$') > 1 && &winwidth < 999
\ | let t:wrcmd = winrestcmd()
\ | set winminwidth=0 winminheight=0 winwidth=999 winheight=999
\ | else
\ | set winminwidth& winminheight& winwidth& winheight&
\ | execute has_key(t:, 'wrcmd') ? remove(t:, 'wrcmd') : 'wincmd='
\ | endif
This gives the following:
- If switch to another window it'll get maximized too.
- It is a global option, so it affects all tabs.
- Some screen space will still be occupied by other window borders.
- 20,685
- 1
- 11
- 24
-
Thanks for this script. – llesh Feb 15 '22 at 08:11