Last Updated: February 25, 2016
·
777
· niclashoyer

gvim always new tab with fish shell

I recently switched to fish shell and I wanted to be able to start gvim from command line, but it should behave just like gedit (just one instance). Then I polished the function a bit. The basic functionality that I had in mind was:

If gvim is not running

gvim

Start a new gvim instance.

gvim <file>

Start a new gvim instance and open file.

If gvim is already running

gvim

Bring the running instance to the front.

gvim <file>

Open file in a new tab inside the running instance and bring gvim to the front.

The Function

Here is what I ended up with, ready to past in your ~/.config/fish/functions/gvim.fish.

function gvim
    if [ (count $argv) -gt "0" ]
        command gvim --remote-tab-silent $argv
        xdotool search --name gvim windowactivate
    else
        ps -A | grep -q gvim
        if [ "$status" -eq "0" ];
            xdotool search --name gvim windowactivate
        else
            command gvim $argv
        end
    end
end