1

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?

llesh
  • 13
  • 2

3 Answers3

0

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
mattb
  • 1,111
  • 4
  • 15
0

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.

Vivian De Smedt
  • 16,336
  • 3
  • 18
  • 37
0

: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:

  1. If switch to another window it'll get maximized too.
  2. It is a global option, so it affects all tabs.
  3. Some screen space will still be occupied by other window borders.
Matt
  • 20,685
  • 1
  • 11
  • 24