Change split orientation

Get a better view by switching between vertical and horizontal splits

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 YouTubefor 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.


Was this useful? Help us improve!

With your feedback, we can improve VimTricks. Click a link to vote: