I'm using vimspector for debugging python, with debugpy. However, I need to source some environment variables before debugging in order for everything to work. How can I set up these env variables before debugging?

In VS code, I used to start the debug. The debug would break, but I could go into the debug terminal, source the env vars, and then it would work.

  • Of course I read the documentation before resorting to asking it here. I couldn't find which field, on the json config file, I should use to setup the env variables. I tried some configs, but neither of them worked. Commented Mar 23, 2021 at 20:38
  • I did forget my customary welcome, so let me say: Welcome to Vi and Vim! I added the doc links for you and for others; if you've seen them and tried to use them, perhaps you could edit your question to include something like "Based on link and link, I tried XYZ but it didn't work"? I tend to find that plugin questions are better answered by the plugin community, though.
    – D. Ben Knoble
    Commented Mar 23, 2021 at 21:12

1 Answer 1


I followed the instructions given by puremourning at https://www.reddit.com/r/vim/comments/mbdt2e/environment_variables_on_vimspector/

I used a shell variable to run a script whose output is the JSON required for the env key; and type coercion to coerce this JSON string into the env map

It is illustrated in puremourning's example:

  • I tried both keys env and env#json in the debug configuration for forwarding environment variables to binary executable, unfortunately neither of them works, my program still failed to retrieve env variables. What is your vimspector version ?
    – Ham
    Commented Jul 24, 2023 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.