Open vim tab in new (GUI) window?
I'd like to move the current tab into a new (visual/real) window in MacVim.
It's probably diffi开发者_StackOverflow社区cult, as:
- there is nothing in the vim help and only very few - not helpful - hits on google
- MacVim does not support it (link, 2009)
So I am wondering if someone has found a way to achieve this?
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 namedDetach
-nR
TODO Fix This is here to avoid the use of swapfiles (because I found no way to suppress the dreadedATTENTION
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, becausex
is the accelerator for Max
imize) - as icing on the cake, vim 7.3 has 'persistent undo'. See e.g.
:se undofile
I don't think this is possible because, when you open a new instance of (g)vim you don't have access to the undo-history of the previous vim instance. All you can do is (in command mode):
:!gvim %
It will open the current file in a new instance of gvim. At least this is all I could think of. I may be wrong
精彩评论