How can I temporarily make the window I'm working on to be fullscreen in vim?

Vim

Vim Problem Overview


I use vim, and usually have more than one vertical/horizental window open, usually editing c++ header files alongside cpp files. How can I temporarily make the window I'm working on to be fullscreen, edit what I want, and then exit fullscreen?

By fullscreen I mean to fit vim window only, and not my total display screen.

Vim Solutions


Solution 1 - Vim

Ctrl+W_ will maximize a window vertically.

Ctrl+W| will maximize a window horizontally.

So far as I'm aware, there is no way to restore the previous layout after these actions, but Ctrl+W= will resize all windows to equal sizes.

Solution 2 - Vim

An option could be to pursue the editing in a new tab. The following command opens the active buffer into a new tab allowing you to see the buffer in the hole vim window.

:tab split

And close the tab when you're done:

:tabc

Edit:

You can always use the following command to use tt as a shortcut (or better add it to your .vimrc):

:noremap tt :tab split<CR>

and close is when you're done :

:wq

Solution 3 - Vim

If I understand what you're asking, I think you'll find the ZoomWin plugin helpful (GitHub). If you've got a bunch of split windows, and you want to temporarily make the current window the only visible one, you can hit <C-w>o. When you want to revert to the previous split state, hit <C-w>o again.

[Edit] Note on key mappings:

The default key mapping for this plugin is <C-w>o, but that conflicts with a default Vim key mapping. By default, that does :only, which makes the current window the only window. If you'd like to retain that functionality, you can remap ZoomWin to another key. I remap it to <C-w>w, because I like to use the :only option as well. Here's my mapping:

nnoremap <silent> <C-w>w :ZoomWin<CR>

Note that this also overrides a default Vim mapping, related to moving to other visible windows (:help CTRL-W_w), but I never used that one anyway.

Solution 4 - Vim

ctrl-w_ - maximize current window

hope this helps you out. :)

And these are the some of the useful commands with can be implemented using VIM editor

:e filename - edit another file

:split filename - split window and load another file

ctrl-w up arrow - move cursor up a window

ctrl-w ctrl-w - move cursor to another window (cycle)

ctrl-w= - make all equal size

10 ctrl-w+ - increase window size by 10 lines

:vsplit file - vertical split

:sview file - same as split, but readonly

:hide - close current window

:only - keep only this window open

:ls - show current buffers

:b 2 - open buffer #2 in this window

Solution 5 - Vim

An awesome plugin for toggling windows fullscreen is vim-maximizer.

After it's installed you can simply use <F3> (default shortcut) to toggle fullscreen on the window.

You can also customize the shortcut keys, for example if you wanted to use <C-w> z (similar to tmux shortcut):

nnoremap <silent><C-w>z :MaximizerToggle<CR>
vnoremap <silent><C-w>z :MaximizerToggle<CR>gv
inoremap <silent><C-w>z <C-o>:MaximizerToggle<CR>

Solution 6 - Vim

I've tried ZoomWin and a few others. The problem is, they all destroy and try to re-create the windows. This is especially problematic with custom plugins like NERDTree, Tagbar and a few others. Icons and fonts are not drawn properly, sizes are messed up etc..

zoomwintab.vim is a simple zoom window plugin that uses vim's tabs feature to zoom into a window inspired by ZoomWin plugin but in a non-destructive manner.

https://github.com/troydm/zoomwintab.vim

I use Tmux, so I mapped it to <leader> z to stay in sync with tmux's <prefix> z

nnoremap <leader>z :ZoomWinTabToggle<CR>

Solution 7 - Vim

Somehow the ZoomWin plugin did not work at all for me, my experience was kind of what arithran says. I couldn't find other plugins so I wrote this:

function! ToggleZoom(zoom)
  if exists("t:restore_zoom") && (a:zoom == v:true || t:restore_zoom.win != winnr())
      exec t:restore_zoom.cmd
      unlet t:restore_zoom
  elseif a:zoom
      let t:restore_zoom = { 'win': winnr(), 'cmd': winrestcmd() }
      exec "normal \<C-W>\|\<C-W>_"
  endif
endfunction

augroup restorezoom
    au WinEnter * silent! :call ToggleZoom(v:false)
augroup END
nnoremap <silent> <Leader>+ :call ToggleZoom(v:true)<CR>

It creates the effect. You use the mapped key (Leader and + in my case) to toggle between maximized / previous layout. If you change to another split in the same tab, maximization turns off.

If you change tabs, the split stays maximized, although somehow it won't cover the complete full width anymore, with the width minimized windows gaining back some 4 columns or something. Anyway it works acceptably for me even with that minor quirk.

edit: somehow it works fine now, must've messed up in some way before.

Solution 8 - Vim

Manoj somewhat answered with a lot more useful info, but as a first step this is what works for me:

:hide: Hide the current buffer - with a two-buffer split, this makes the other buffer full screen. Unlike :only, this command does not close unmodified buffers so you can unhide them.

:unhide: Re-create splits for each open buffer

The unhide command does not restore the previous layout, so you will have to manually rearrange your windows if needed ex. using one of these for simple vertical/horizontal splits:

CTRL-W H: Move window to the far left
CTRL-W J: Move window to the very bottom
CTRL-W K: Move window to the very top
CTRL-W L: Move window to the far right

These are the same keys used for navigation (cursor when used alone, and CTRL-W + lowercase to move between windows - arrow keys may work as well for navigation). The CTRL-W + uppercase ones move the current window instead.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTed RodView Question on Stackoverflow
Solution 1 - Vimuser149341View Answer on Stackoverflow
Solution 2 - VimMickView Answer on Stackoverflow
Solution 3 - VimJim StewartView Answer on Stackoverflow
Solution 4 - VimManojView Answer on Stackoverflow
Solution 5 - VimMiguel MotaView Answer on Stackoverflow
Solution 6 - VimArithranView Answer on Stackoverflow
Solution 7 - VimataView Answer on Stackoverflow
Solution 8 - VimThomas Guyot-SionnestView Answer on Stackoverflow