4

Is there a way to make vim (or nvim) open all new splits vertically by default? There's splitright to control which side vertical splits open on, but as far as I can tell there's no built in option to make splits vertical by default. Does anyone know of a workaround? I found one for the help command specifically, but I'm looking for something that will make all splits vertical.

2

There's not really an option that does that.

You can accomplish that by using an autocmd, more specifically catching the WinNew event and moving the newly created window so that it's a vertical one rather than horizontal.

For example:

autocmd WinNew * wincmd L

(Don't forget to add this to an appropriate augroup and clear the augroup first, so if you reload your vimrc it won't duplicate the rules.)

Note also that this isn't always the same as using vertical, since wincmd L will always make the new window the rightmost vertical top-level window. It's also somewhat hard to override it (you can use the :noautocmd modifier, but that will disable all autocmds.)

But perhaps this is close enough to what you're looking for.

| improve this answer | |
  • 1
    This has gotten me closer to the behavior that I want than any other suggestion I've seen; thanks. – Morgan May Feb 8 at 3:16
  • You're very welcome @MorganMay! Glad I could help. By the phrasing of your question, I felt this might have been what you were after... – filbranden Feb 8 at 4:22
6

:split, :new and such are "horizontal" commands. But they all have "vertical" counterparts: :vsplit, :vnew etc. Take a habit to choose the right ones.

Also, you're not allowed to redefine Vim builtin commands (except a few starting with a capital letter), but, if you wish, you can redefine key mappings, such as nnoremap <c-w>n <c-w>v and so on.

| improve this answer | |
3

Unfortunately, this is not possible and not all commands that open windows (e.g. :sp), have vertical counterparts (e.g. :vsp).

So a couple of years ago, I made the splitvertical patch, that introduces the 'splitvertical' option.

Unfortunately, it has never been included.

| improve this answer | |
1

There’s no option because there’s an specific command: :vsplit (:vs). It takes a filename as an argument, just as :sp does. In fact the option you mentioned, splitright, affects the behaviour of :vs.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.