On 14/03/14 08:20, Jürgen Krämer wrote:
>
> Hi,
>
> Viktor Kojouharov wrote:
>> To easily use the remote-expr feature. You need to start a new
>> instance of vim and point it to the current running vim server. And I
>> need the full executable path in order to start the remote-expr. Vim
>> is usually in the path on linux systems, but that's not the case on
>> windows and macvim
>>
>
> at least on Windows Vim puts its own directory at the end of the %PATH%
> environment variable. You can check this with ":echo $PATH". So there is
> no need to use a full path to the Vim executable.
>
> jkr
>
On Linux, the Vim executable is placed in one of the directories which
are already in the normal $PATH. Normally the one related with where the
runtime files are. For instance, the Vim defaults (for version 7.4) are:
$VIM = /usr/local/share/vim
$VIMRUNTIME = /usr/local/share/vim/vim74
executable = /usr/local/bin/vim
But that /usr/local/bin directory might contain a lot of softlinks such as
view -> vim
ex -> vi
vi -> vim
gvim -> vim
gview -> gvim
vimdiff -> vim
gvimdiff -> gvim
etc., all ultimately pointing to the binary executable, and sometimes in
relays as in the above example for ex, gview and gvimdiff (on my system,
"vi" is not a softlink but a Tiny build with no optional features). So
if you want to know not only from which directory Vim was loaded but
also under which name… wait… ah no, the usual shell convention is that
argv[0] is the program name as invoked, but inside Vim, argv(0) seems to
be what the shell would call argv[1].
Ah, there, gotcha: v:progname is the program name (with path removed)
under which Vim was invoked. So, under Linux, if $VIMRUNTIME includes
the path element "/share/" (it usually does), remove it (but not its
leading slash) and all after it, and append first "bin/" then v:progname
in its stead. The result is "usually" the full path to the executable;
but in some cases it might not. If $VIMRUNTIME does not include /share/,
I don't know how to go from there to the executable directory. And I use
$VIMRUNTIME rather than $VIM because $VIM is not always $VIMRUNTIME/.. —
for instance, the Vim which comes precompiled with my Linux distro uses
/etc/site for $VIM but /usr/share/vim/current (a link to vim74 in the
same directory) for $VIMRUNTIME. _That_ version of Vim (7.4.52) lives as
/bin/vim but there is also a softlink /usr/bin/vim pointing to it. My
own (and more recent) /usr/local/bin/vim (currently 7.4.205) is before
them in the $PATH so by default it will be the one invoked. For the
other I have a softlink /bin/vim-suse -> vim to unmask it when
needed(the target of a relative softlink is relative to where the
softlink itself is found). And when I invoke that softlink, v:progname
is "vim-suse" which is the name under which it was invoked, before
following the softlinks. QED.
And, yes, it is quite possible (on Linux, and, I think, on the Mac) to
have several versions of Vim (as in my case 7.4.52 and 7.4.205) living
peacefully on one machine, so `which vim` (or `type -P vim` if "which"
is undefined) is not necessarily the right answer. It might, just this
time, be something further down the $PATH.
Best regards,
Tony.
--
A beer delayed is a beer denied.