I've found the --remote-tab-silent
option in an alias to work for the most part except when I've wanted to pass options to gvim (e.g. gvim --serverlist
) - in which case gvim treats the option as a literal filename which is no good as firstly that's not what you wanted and secondly you have to clean up the buffers from your now tainted vim session.
It's not practical to use another alias or resolve vim
/gvim
differently for some cases such as the following.
gvim
gvim /path/to/files
gvim --serverlist
gvim -p /path/to/file1 /path/to/file2
gvim -t tag filename
My solution is the following wrapper script around gvim
(~/.bin/gvim
) as Tom Veiner suggests but this will only use an existing server if none of the arguments are gvim
options - otherwise, a new server is created.
#!/usr/bin/perl
use v5.10;
sub gvim { exec { '/usr/bin/gvim' } '/usr/bin/gvim', @_; }
if (scalar @ARGV) {
unshift @ARGV, '--remote-tab-silent' unless /^--?/ ~~ @ARGV;
gvim @ARGV
}
else {
chomp(my $serverlist = `gvim --serverlist`);
if (length $serverlist) {
gvim '--remote-send', '<Esc>:tabnew<CR>'
} else { gvim }
}