Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open vim tab in new (GUI) window?

Tags:

vim

macvim

I'd like to move the current tab into a new (visual/real) window in MacVim.

It's probably difficult, 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?

like image 209
h2459jl Avatar asked May 25 '11 11:05

h2459jl


2 Answers

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
  1. save all current windows, mappings, settings (:he mksession)
  2. close the tab we are about to detach
  3. 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 Maximize)
  • as icing on the cake, vim 7.3 has 'persistent undo'. See e.g. :se undofile
like image 167
sehe Avatar answered Oct 02 '22 15:10

sehe


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

like image 25
sica07 Avatar answered Oct 02 '22 15:10

sica07