sponsor Vim development Vim logo Vim Book Ad

quit-another-window : Quickly close another window and keep working in current window

 script karma  Rating 0/6, Downloaded by 1186  Comments, bugs, improvements  Vim wiki

created by
Dmitry Frank
script type
Often I need to close some another window and keep working in the current window.
For example, when I read some help in the upper window, and edit code in the lower
window. At one time, I decide to close help window. To do it,
i have to press "Ctrl_W k :q".

Not very short. And this is not the worse variant.
Another variant:

|      help           |                        |
|     window      |                        |
|                         |     current      |
+-----------------+     window     |
|                         |                        |
|                         | <cursor>       |
|                         |                        |
|                         |                        |

Focus is in the 'current window', cursor is on the <cursor> sign.
I want to close 'help window' and keep working in current window.

That's what i need to do:

Ctrl_W h Ctrl_W k :q Ctrl_W l

This is pretty long!
So, I wrote this plugin to make it easy.

It provides 5 commands.

Firstly, four commands for most-frequently actions:

      :Qh means "close left window and go back"
      :Qj means "close lower window and go back"
      :Qk means "close upper window and go back"
      :Ql means "close right window and go back"

And one universal command:
      :Q <args>, where <args> is movement commands to needed window.
      For example, ":Q hk" means "Go to the left window, then go to upper window,
                                  close it and go back to source window"

      So, this long long command "Ctrl_W h Ctrl_W k :q Ctrl_W l"
      is truncated to short expression: ":Q hk"

There's one optional dependency: CmdAlias plugin (vimscript #746).

If CmdAlias is installed, then lowercased aliases of commands will be available:   :qh, :qj, :qk, :ql, :q <args>.
I found it useful.

Please NOTE:

1) if :Q without arguments is passed, then current window becomes closed.
   (to provide compatibility of lowercased command :q)

2) If argument is passed, but target window is the same as current window, then
   no window will be closed.
install details
Use pathogen.

Or just unpack contents of the package in your .vim directory.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
quit_another_window.tar.gz 1.04 2011-08-30 7.0 Dmitry Frank Added another useful shortcut for the universal command can be overridden via

      nmap <silent> <C-z> <Plug>QAnotherWin

<C-z> is default. This shortcut waits you enter h,j,k,l as much as you want
and finish your command with <Space>. The result will be same as :Q <args> but

This functionality was added by Ümit Kablan.
quit-another-window-1.03.tar.gz 1.03 2011-07-18 7.0 Dmitry Frank Added "!" ability to commands.
quit-another-window-1.01.tar.gz 1.02 2011-05-02 7.0 Dmitry Frank Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.