How do I move an existing window to a new tab?
VimVim Problem Overview
Is there a way to take an existing window (split) and put it into a new tab?
Vim Solutions
Solution 1 - Vim
As well as the previously suggested :tabedit
approach, a quicker way of doing it is (in normal mode) to hit Ctrl-W Shift-T. Ctrl-W is the general prefix for a wide variety of window manipulation commands.
See:
:help Ctrl-W_T
:help Ctrl-W
Solution 2 - Vim
Try
:tabedit %<CR>
Solution 3 - Vim
This moves the newest buffer in a new tab and restores the previous buffer in the current tab. I use this after dragging a new file into my Gvim
:sbp |wincmd p| wincmd T
You can map it like that to Ctrl-Backspace
:nnoremap <C-BS> :sbp<bar>wincmd p<bar>wincmd T<CR>
it performs especially well with
:set switchbuf=usetab
Solution 4 - Vim
I have been using this which gives you two functions which can be bound to a pair of hotkeys or commands, and which works quite intuitively. I am pretty sure it offers behavior even more friendly than e.g. Ctrl-W_T
.
For example, when multiple windows are open in multiple tabs, using this function allows you to specifically move the current window to the next or previous tab, and if you move something to before the first tab or to after the last tab, then it turns into a whole new tab.
This means if you have 2 tabs, each having a single window, then moving the first tab's window to the right will combine it with the second tab to result in one single tab with two windows. I don't know how convoluted this operation is to achieve using traditional commands.
What this means is that a single pair of move commands allows for both shifting windows around the tabs, splitting windows out into tabs (by pushing a window out to the end) and joining separate tabs into windows inside of a single tab, pretty much everything you could possibly want, short of positional arrangement (which is a separate topic and which the built in Ctrl-W
+Shift-HJKL
commands work fine for).