To switch from vertical split to horizontal split fast in Vim

Viewed 164473

How can you switch your current windows from horizontal split to vertical split and vice versa in Vim?

I did that a moment ago by accident but I cannot find the key again.

8 Answers

Vim mailing list says (re-formatted for better readability):

To change two vertically split windows to horizonally split

Ctrl-w t Ctrl-w K

Horizontally to vertically:

Ctrl-w t Ctrl-w H

Explanations:

Ctrl-w t makes the first (topleft) window current

Ctrl-w K moves the current window to full-width at the very top

Ctrl-w H moves the current window to full-height at far left

Note that the t is lowercase, and the K and H are uppercase.

Also, with only two windows, it seems like you can drop the Ctrl-w t part because if you're already in one of only two windows, what's the point of making it current?

In VIM, take a look at the following to see different alternatives for what you might have done:

:help opening-window

For instance:

Ctrl-W s
Ctrl-W o
Ctrl-W v
Ctrl-W o
Ctrl-W s
...

Horizontal to vertical split

Ctrl+W for window command,

followed by Shift+H or Shift+L


Vertical to horizontal split

Ctrl+W for window command,

followed by Shift+K or Shift+J

Both solutions apply when only two windows exist.

After issuing the window command Ctrl+W, one is basically moving the window in the direction indicated by Shift+direction letter.


Opening help in a vertical split by default

Add both of these lines to .vimrc:

cabbrev help vert help
cabbrev h vert h

cabbrev stands for command abbreviation.

:vert[ical] {cmd} always executes the cmd in a vertically split window.

Related