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.

Tarrasch
  • 208

1 Answers1

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.

grawity
  • 501,077