vim-quit-another-window

Vim plugin that offers a way to close arbitrary window without bothering to leave current window.

Rationale

During my daily vimming, I often need to close some another window and keep working in the current window. And I want to do it without bothering to leave my current window.

For example, when I read some help in the upper window, and edit code in the lower window. At some moment, 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 case.

Another case:

+-----------------+-----------------+
|      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 the current window.

Here's what I need to do: Ctrl_W h Ctrl_W k :q Ctrl_W l

That is a way too long! So, I wrote this plugin to make me feel better.

Plugin details

The plugin 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> are 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. If it is installed, then lowercased aliases of commands will be available: :qh, :qj, :qk, :ql, :q <args>. I found it much more useful than capitalized ones.

Please note the following:

  • If :Q without arguments is passed, then current window becomes closed. (to provide compatibility of lowercased command :q)
  • If argument is passed, but target window is the same as current window, then no window will be closed.

Download

Currently, the plugin is hosted at vim.org only: quit-another-window.

Discussion

Andrey, 2019/03/09 21:35

Could we have some mappings in the plugin for Normal mode?

Dmitry Frank, 2019/03/11 08:52

Since there are no default mappings for closing current window either, I can't think of any mappings which it would make sense for the plugin to provide by default.

But you can always create your own mappings.

Marcel Marré, 2019/11/19 16:08

I am not sure whether I misunderstand something and miss the point, but there is a way to close the current window in Normal mode, namely CTRL_W q. And, in fact, you can start it with a “count”, which can be the window number (starting in upper left with 1, going down and then right, although I have not fully tested how it behaves when you have quite irregular windows due to multiple splits in different directions).

Hence, when I have four windows in the corner of the screen, I can close the bottom right with 4 CTRL_W q. Or, to use the example in the post, 1 CTRL_W q.

Enter your comment (please, English only). Wiki syntax is allowed:
   __    _  __   ____  __  __   __  ___
  / /   | |/_/  / __/ / / / /  /  |/  /
 / /__ _>  <   / _/  / /_/ /  / /|_/ / 
/____//_/|_|  /_/    \____/  /_/  /_/
 
projects/vim-quit-another-window.txt · Last modified: 2015/09/09 08:46 by dfrank
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0