lokhura
lokhura

Reputation: 25

How to correctly set PATH in gvim?

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.

Upvotes: 2

Views: 4723

Answers (3)

techcraver
techcraver

Reputation: 411

I tried this:

let $PATH .=':/path/to/bin:/path/to/another/bin'

Then it started working fine. I was trying to setup vim-go (golang support) for vim. I had been having issues with it since vim-go was complaining that go executable isn't in path. This has been the issue with vim-gtk. After I set the above configuration in .vimrc file issues got resolved.

Upvotes: 0

Richard
Richard

Reputation: 3100

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

Upvotes: 1

romainl
romainl

Reputation: 196476

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

Upvotes: 2

Related Questions