Change split orientation


Splitting your screen in Vim is a powerful way to compare to files, work on code side-by-side with its test, or just get more done. Pro Vim users work more efficiently by having multiple files open and on screen at once. Vim has a number of commands you should internalize for working with splits, some of which we’ve covered before:

But one I often need and always forget is how to switch splits from side by side orientation (vertical splits) to top and bottom orientation (horizontal splits). To change your split orientation use the command that prepends all split commands: ctrl-w followed by either K or H:

  • ctrl-w H – Change horizontal splits to vertical
  • ctrl-w K – Change vertical splits to horizontal

You can watch a screencast of this in action below. The gif is linked to the YouTube video which is a little longer and with audio. (Keep the feedback coming, thank you! 🙏)

Subscribe to us on YouTube for more upcoming video VimTricks. And follow us on Twitter for more text posts from the archives.

If you have trouble remembering H and K, you may wish to add custom mappings to your .vimrc like so:

" change vertical to horizontal with -
noremap <c-w>- <c-w>t<c-w>K
" change horizontal to vertical with |
noremap <c-w>\| <c-w>t<c-w>H

This will map ctrl-w - to switch vertical splits to horizontal ones. And ctrl-w | will change horizontal splits to vertical ones. The character choice is designed to help you remember them, but do note that these will overwrite some existing split commands so might not be the best choices. You can always choose different key mappings, simply change the first argument to another choice.

How useful was this tip?

Average rating 3.3 / 5. Vote count: 399

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

97 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts