I have used VS Code and liked the way we can drag-drop the window to the right to create a vertical split.

Sometimes I open many files with vim (vim -p *py). When going through the tabs, I feel like this specific tab should be a vertical split instead.

Forgetting the drag and drop part, how can I make my current tab to be splitted vertically? (I've had splitright set)


As suggested by sparrow1029, :vs sb# works, but keeps the former buffer intact, can we delete it somehow? Maybe some function bound to keystroke(s)?

  • Okay, so I found these functions on the vim wiki. Replace the calls to sp in the functions with vs, and map them to a keystroke, and it should have the desired effect. If it works for you, I will update my answer :) – Sparrow1029 Aug 31 '19 at 2:45
  • FYI: the hierarchy in Vim is tabs contain windows (which you're calling a vertical split), and windows show buffers, which exist independently of tabs and windows (different windows may show the same buffer, for instance). With that in mind, you might want to rephrase your question in a way that makes more sense in Vim. – muru Aug 31 '19 at 3:58
  • ":vs sb# works, but keeps the former buffer intact, can we delete it somehow?" Is :argdelete what you're looking for? That will remove it from arguments, so that :n and :prev will not go through that particular buffer anymore... – filbranden Sep 3 '19 at 1:07
  • I want the buffer to be killed. – Santosh Kumar Sep 3 '19 at 6:21

If you read this article, it will help you understand the differences between buffers, windows, and tabs in vim.

This answer on superuser has one solution:

The vs and vsplit commands take a filename as an argument like :vs somefile to open a file in a vertical split.

To put an existing buffer in a split window you use the sb# command (where # is the buffer number). Splits in VIM default to horizontal, to change this, prefix your command with vert which forces a vertical split of the next split command.

:vert sb#

where # is the number of the buffer you want to show as a split in the current window.

To show your currently active buffers you can use :ls! or :buffers.

Solution #1 on the previously linked article about vim windows/tabs/buffers suggests airline plugin for vim to show currently open buffers as you might expect 'tabs' to work in other editors.

| improve this answer | |
  • Umm... I was already aware of the differences. The answers on the previous question were helpful. But I was looking for kinda a function hooked to a keybinding to do the split for current buffer automatically. – Santosh Kumar Aug 31 '19 at 1:37
  • Gotcha! Sorry, I only found out recently about all the differences, was trying to be helpful. Would you want it to split with the next or previous buffer? Or be able to specify? – Sparrow1029 Aug 31 '19 at 1:57
  • I'll update my question with details. – Santosh Kumar Aug 31 '19 at 2:00

TL;DR: Use buffers instead of tabs in Vim.

If I understand correctly, the problem is that you want to keep that file in a split window while you change the file on the other side, so that you can keep the other file visible.

It turns out that tabs in Vim don't really work that way, tabs are collections of windows, so whenever you change tabs, you'll switch all windows at once. That's quite useful if you're working on separate sets of windows at the same time.

But it looks like that's not what you want, since you want to change the file in a single window at a time.

For that purpose, you'll want to use buffers in Vim, and not tabs. Buffers are the Vim features that most closely ressembles tabs in other editors such as VS Code.

Simply use vim *.py when opening files (without the -p option that opens them in tabs), and navigate them using :n and :prev (or :N). You can then split with :vs or :sp and use the Ctrl-W commands to switch and reorganize windows.

Employ tabs if you ever find yourself wanting to have a separate set of windows, or perhaps focus on a single file full-screen for a while, while at the same time preserving the previous window setup you had, coming back to it at any time.

You might want to read :help buffers (linked here), it goes into quite a bit of detail into all these concepts.

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