1
votes

When I run vim from terminal PATH is the same as my terminal. But when I run gvim PATH is not reading properly.

Currently I'm using this fix to launch gvim, but it feel dirty:

bash -lc gvim

I tried adding the path to vimrc with:

let PATH='/home/user/.rvm/gems/ruby-2.1.0/bin:/home/user/.rvm/gems/ruby-2.1.0@global/bin:/home/user/.rvm/rubies/ruby-2.1.0/bin:/opt/project-neon/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/user/.cabal/bin:/home/user/.rvm/bin'

But it didn't work like I expected.

This doesn't work either:

set shell=bash\ --login

How can I make this work nicely in my vimrc?

I'm using Ubuntu.

2
You should avoid having such a long PATH. I would suggest adding $HOME/bin/ to your PATH and putting symlinks there. And you should set your PATH in your .bashrc ... - Basile Starynkevitch
I set the PATH in bashrc aldready but it doesn't work. Only the command bash -lc gvim works for some reason... - lokhura
You might need to logout and login again after changing $HOME/.bashrc and you should check, e.g. with echo $PATH in a terminal, that your PATH is what you want. I guess your question is unrelated to vim actually! - Basile Starynkevitch
I mean that PATH and bashrc work on terminal fine, but not on vim unless I use that command. My PATH works fine everywhere else. It is vim related, I saw question with similar problem, but on OSX, but didn't solve the issue. - lokhura
A well configured vim don't change the PATH it has inherited at startup time. - Basile Starynkevitch

2 Answers

2
votes

You don't change your PATH from Vim. It is inherited from the process that launches Vim and that's there, outside of Vim that you must fix your issue.

You didn't tell us how and where you set your PATH, what desktop environment (if any) or even what value you get in GVim, by the way.

-- edit --

When you lauch GVim from the command-line, it inherits your shell's environment variables and you should get the same $PATH with $ gvim as you do with $ vim.

When you start GVim from a menu or an icon, it inherits the desktop environment's PATH which is defined regardless of your shell's PATH so the output of :echo $PATH is different from what you should get in my shell.

In my opinion, the most effective way to get GVim to honor your custom PATH is simply to change the Exec line in its gvim.desktop file from:

Exec=gvim -f %F

to:

Exec=env PATH=/your/complete/path gvim -f %F
1
votes

I understand this is already answered, but the following may help someone else :

If you set your PATH in your ~/.profile then gvim will pick it up in from the logged in session - without having to modify the gvim.desktop file with an explicit path. (But you do need to re-login for it to take effect).

See Ubuntu Session-wide environment variables for more information