This happens to me semi-frequently. I have two tabs open, and I would like to merge them into one tab with a vertical split. Essentially, I want to do the opposite of CTRL-w_T. Right now, I have to this:

:wq<cr><C-w>v:browse old<cr>q1<cr>

Is there any more convenient way to do this? If there isn't a builtin way, I wouldn't be opposed to adding a vimscript function, or installing a plugin.


2 Answers 2


Assuming I understand you correctly, try the following:

function! MergeTab()
    let bufnums = tabpagebuflist()
    hide tabclose
    topleft vsplit
    for n in bufnums
        execute 'sbuffer ' . n
        wincmd _
    wincmd t
    wincmd =
command! MergeTab call MergeTab()

It will merge all windows in a tab into a vertical split at the left hand side of the following tab (or the preceding tab if you happen to be on the last tab).

There might be issues if you run out of room, but you'll still have your buffers in the buffer list.

  • You could let it take optional arguments. Then if there was an argument go to that tab, otherwise use this behavior. Just an idea for robustness.
    – Tumbler41
    Jul 14, 2016 at 21:34
  • Yeah, that might be nice if that situation arises a lot. Otherwise you could just do a :tabmove first.
    – Antony
    Jul 14, 2016 at 21:42

Dirty solution (only works if you have exactly two tabs):

vim -p file1 file2

:exe 'normal! gt' | exe 'vsplit ' . bufname('#') | exe "normal! gt"| q


  • Move to the other tab to make the first tab the alternate file,
  • vsplit against the alternate file,
  • Move to the other tab again and quit.

A little better solution, it works when you have more tabs but leaves a global variable hanging:

:let this_tab = bufname('%') | exe 'normal! gt' | exe 'vsplit ' . this_tab | exe "normal! gT"| q | unlet this_tab

Explanation (same as above but):

  • Saves the buffer on the tab on the left,
  • Uses the saved buffer when performing vsplit.

(the hanging variable can be avoided by making a function)

  • This very much worked for me, thanks a ton!
    – smohamed
    Jan 24, 2017 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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