Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having trouble with gvim and tabs. Using Ubuntu, there is the gedit editor, which opens files in new tabs, but gvim opens a new window for each file i open. I definitely prefer to have tabs, just like every other application I use. Having 5 gvim windows open simultenously overwhelms me.

So, is there any way to edit .gvimrc to make it open new files in new tabs instead of opening a new gvim window? I definitely prefer a .gvimrc solution over a Nautilus solution.

share|improve this question
up vote 2 down vote accepted

Use the client/server feature of vim/gvim.

gvim --remote-tab myfile

This works for both terminal and GUI versions of vim, as long as they are compiled (vim --version) with the +clientserver feature. (Optionally add --servername foo to set the instance name, which defaults to GVIM.)

Unfortunately, you cannot do this from .vimrc. You will have to, either:

  • write a wrapper script, for example, ~/bin/gvim:

    exec /usr/bin/gvim --remote-tab-silent "$@"

    (--remote-tab-silent will cause a new server to be silently started if needed)

  • modify the gvim.desktop file to include the server commands:

    $ mkdir -p ~/.local/share/applications
    $ cp {/usr,~/.local}/share/applications/gvim.desktop
    $ vim -e ~/.local/share/applications/gvim.desktop
    :/^Exec=/ s/gvim/& --remote-tab-silent/

The wrapper script method will probably cover more cases than editing the .desktop file.

share|improve this answer
Thanks! I used the wrapper script method and it works perfectly! Using a wrapper script is more portable, as I can clone my dotfiles anywhere and tabbed gvim will then just work. – Tarrasch Sep 13 '11 at 8:32
For anyone having problems with the gvim.desktop method, try using this exec line: Exec=bash -c "gvim --remote-tab-silent %f || gvim". This makes the dash icon still work. Also, if you're getting a spinning cursor for a long time after opening gvim, set StartupNotify to true. – nkorth Mar 9 '14 at 20:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .