[vim] Cancel split window in Vim

I have split my windows horizontally. Now how can I return to normal mode, i.e. no split window just one window without cancelling all of my open windows. I have 5 and do not want to "quit", just want to get out of split window.

This question is related to vim split window

The answer is


Okay I just detached and reattach to the screen session and I am back to normal screen I wanted


to close all windows but the current one use:

CTRL+w, o

That is, first CTRL+w and then o.


The command :hide will hide the currently focused window. I think this is the functionality you are looking for.

In order to navigate between windows type Ctrl+w followed by a navigation key (h,j,k,l, or arrow keys)

For more information run :help window and :help hide in vim.


To close all splits, I usually place the cursor in the window that shall be the on-ly visible one and then do :on which makes the current window the on-ly visible window. Nice mnemonic to remember.


Edit: :help :on showed me that these commands are the same:

  • :on
  • :only
  • CTRL-w CTRL-o
  • And yes, also CTRL-W o has the same effect (as Nathan answered).

Each of these four closes all windows except the active one.


Two alternatives for closing the current window are ZZ and ZQ, which will, respectively, save and not save changes to the displayed buffer.


I found that ctrl + w to the window you want to close, then just do :q. This works for me.


Just like the others said before the way to do this is to press ctrl+w and then o. This will "maximize" the current window, while closing the others. If you'd like to be able to "unmaximize" it, there's a plugin called ZoomWin for that. Otherwise you'd have to recreate the window setup from scratch.


From :help opening-window (search for "Closing a window" - /Closing a window)

  • :q[uit] close the current window and buffer. If it is the last window it will also exit vim
  • :bd[elete] unload the current buffer and close the current window
  • :qa[all] or :quita[ll] will close all buffers and windows and exit vim (:qa! to force without saving changes)
  • :clo[se] close the current window but keep the buffer open. If there is only one window this command fails
  • :hid[e] hide the buffer in the current window (Read more at :help hidden)
  • :on[ly] close all other windows but leave all buffers open

I understand you intention well, I use buffers exclusively too, and occasionally do split if needed.

below is excerpt of my .vimrc

" disable macro, since not used in 90+% use cases
map q <Nop>
" q,  close/hide current window, or quit vim if no other window
nnoremap q :if winnr('$') > 1 \|hide\|else\|silent! exec 'q'\|endif<CR>
" qo, close all other window    -- 'o' stands for 'only'
nnoremap qo :only<CR>
set hidden
set timeout
set timeoutlen=200   " let vim wait less for your typing!

Which fits my workflow quite well

If q was pressed

  • hide current window if multiple window open, else try to quit vim.

if qo was pressed,

  • close all other window, no effect if only one window.

Of course, you can wrap that messy part into a function, eg

func! Hide_cur_window_or_quit_vim()
    if winnr('$') > 1
        hide
    else
        silent! exec 'q'
    endif
endfunc
nnoremap q :call Hide_cur_window_or_quit_vim()<CR>

Sidenote: I remap q, since I do not use macro for editing, instead use :s, :g, :v, and external text processing command if needed, eg, :'{,'}!awk 'some_programm', or use :norm! normal-command-here.


Examples related to vim

Why does using from __future__ import print_function breaks Python2-style print? How to run vi on docker container? How can I install MacVim on OS X? Find and replace strings in vim on multiple lines Running Python code in Vim How do I set the default font size in Vim? Move cursor to end of file in vim Set encoding and fileencoding to utf-8 in Vim How to select all and copy in vim? Why I've got no crontab entry on OS X when using vim?

Examples related to split

Parameter "stratify" from method "train_test_split" (scikit Learn) Pandas split DataFrame by column value How to split large text file in windows? Attribute Error: 'list' object has no attribute 'split' Split function in oracle to comma separated values with automatic sequence How would I get everything before a : in a string Python Split String by delimiter position using oracle SQL JavaScript split String with white space Split a String into an array in Swift? Split pandas dataframe in two if it has more than 10 rows

Examples related to window

CMD command to check connected USB devices Get viewport/window height in ReactJS the MySQL service on local computer started and then stopped AngularJS $watch window resize inside directive tkinter: Open a new window with a button prompt window.close() doesn't work - Scripts may close only the windows that were opened by it Send parameter to Bootstrap modal window? How do I insert a JPEG image into a python Tkinter window? Installing Python 2.7 on Windows 8 How do I get the offset().top value of an element without using jQuery?