The closest I think you can come is using mksession
This will have several drawbacks (like, initially the secondary session will open a few more buffers than ultimately desired).
However, it will preserve your mappings, settings, history, window layout (if you had multiple windows inside the current tab, they will all get cloned).
If this idea tickles your fancy, you could look at creating a script that will filter parts out of the session file (which is Yust Another Vim Text Script)
:mksession! $HOME/detach.vim
:tabclose
:silent! !gvim remote --servername Detach -nR +'silent! source H:\detach.vim' +tabonly
- save all current windows, mappings, settings (
:he mksession
)
- close the tab we are about to detach
- clone the session (detach.vim) into a remote vim
:silent!
(try not to talk too much)
!gvim remote --servername Detach
; launch a new remote Vim server if it doesn't yet exist, or talk to the existing server named Detach
-nR
TODO Fix This is here to avoid the use of swapfiles (because I found no way to suppress the dreaded ATTENTION
messages[1]). However, this may be unsafe advice depending on your situation, which is why I also include -R
for read-only mode
+'silent! source H:\detach.vim' +tabonly
-- In the remote vim, source the session to clone, and keep only the active tab (that was already closed in step 1.)
A little rough around the edges, for sure, but quite close to what you intended, I feel.
If you are comfortable, you can drop the -nR
flags and just click through a few annoying swapfile attention messages (keyboard: Q).
[1] :he ATTENTION
Post-scripts:
- on windows you might want to use
:silent! !start /b gvim ....
in case you have terminal windows sticking around
- also on windows, you might get annoying behaviour if the resulting gvim window is too small. The
:simalt ~x
sequence is one hacky way to maximize the window (assuming English UI, because x
is the accelerator for Max
imize)
- as icing on the cake, vim 7.3 has 'persistent undo'. See e.g.
:se undofile