Vimr: Pass all env vars to nvim when launching using `vimr` (would result in VirtualEnv support)

Created on 23 Mar 2018  路  8Comments  路  Source: qvacua/vimr

I could not seem to find a way to get vimr to respect virtual environments. Usually if I am working on a python project and have a virtual environment set up with venv, running vim and then running :!source bin/activate will set the virtual environment within vim.

This did not seem to work with vimr (launching from dock, then running the source command), as the python version stays as my system's one, and none of the venv libraries are in my python path.

Most helpful comment

vimr --cur-env will create a new window with the current environment variables.

All 8 comments

the vimr program isn't following best practices with the shebang line. The Vimr.app doesn't have access to anything but the system shell. In order to bootstrap into a virtualenv, modify the generated vimr script first line by changing #!/usr/bin/python to #!/usr/bin/env python. This will cause bootstrap to add in the python environment from the virtualenv python and make things work.

Took me a while to figure this out because it was causing all of my lexer plugins to be unable to find my virtualenv classes and thus breaking my whole IDE.

You can't use CMD-N to open new vimR windows though. You'll need to use the vimr command from within the virtualenv. That's fine for me because that's how I did things before with MacVim

It's also not compatible with python3 environments. I'm about to issue a PR to fix that, but I have to integrate my altered vimr script

Well, it seems that this issue is related to the VimR.app and bootstrap still works provided that you kill the app and use the console script to open it (even the old one).

The new script works fine, but isn't really required (and doesn't really fix anything) so I'm not issuing a PR unless there is a pressing need.

If we want to pass the whole set of environment variables, we have to change how we launch the background nvim process.

+1

@SkyLeach The reason I'm using #!/usr/bin/python is to explicitly use the system Python of macOS. This way I know that I'm using Python 2.7.X. The current plan is to add --cur-env option to vimr. It would then store all environment variables to a temporary JSON file, which will read by the UI. I guess this will be enough to support virtualenv, which, afaik, extends the PATH variable to set the Python binary. I'll test the implementation a bit tomorrow and build a snapshot.

Please try https://github.com/qvacua/vimr/releases/tag/snapshot%2F283 (you have to re-install vimr)

vimr --cur-env will create a new window with the current environment variables.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nornagon picture nornagon  路  3Comments

romaninsh picture romaninsh  路  7Comments

laur1s picture laur1s  路  5Comments

tjdoc picture tjdoc  路  6Comments

TravisDart picture TravisDart  路  7Comments