2

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.

1 Answer 1

2

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:

    #!/bin/sh
    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/
    :wq
    $
    

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

2
  • 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, 2011 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, 2014 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.