I am trying to use variables from SHELL inside my Vim configuration file, now, I have researched how to do this and asked ChatGPT about how as well. It is possibly due to the specific environment here on our campus which might cause issues.

What I've tried

let var = $var

let var = system('echo $var')

let var = system('zsh "echo $var"')

This one messes with my startup script since it runs a new instance of ZSH (so unclear if it otherwise would work, but I can probably assume it would not)

let var = system('zsh -i -c "echo $var"')

Here's how I have been calling it to check it's value:

echom "test: " . var

also tried:

echom "test: " . $var


I run ZSH, using ohmyzsh on top of that.

I can echo the variable in shell just fine, from within a Vim buffer or terminal.

The variable itself that I am trying to call is set in my zshrc like so:

export $var
  • Welcome to Vi and Vim!
    – D. Ben Knoble
    Commented Oct 6, 2023 at 2:04
  • 2
    I believe the problem is export $var that should be export var instead. Commented Oct 6, 2023 at 4:43
  • @Friedrich your kind is the exact reason I am too afraid to even ask anything on any stack sites, I carefully crafted my question, making absolutely sure it was up to standard, yet, still, this... "while adding nothing", I found it relevant because in case what I was doing was correct, that could also have been the issue, but I wouldn't know what exact details to provide, just so that people could keep an open mind and ask details if that were true. It ended up being irrelevant, but I could not have known this because I did not see my simple syntax error, hence the question overlooking it.
    – Ella H
    Commented Oct 6, 2023 at 17:40
  • 1
    I do think that’s a bit nitpicky @Friedrich, but the request was mostly kindly worded. Ella, I still recommend the tour and other helpful informational pages! Gracefully giving and receiving critique is hard, and I think both of you want the question to be the best it can be. The good news is that I think we’ve solved the problem? If so, I will vote-to-close this (no harm done, Ella, so please come back and ask more Vim questions when you have them!).
    – D. Ben Knoble
    Commented Oct 6, 2023 at 20:44

1 Answer 1


To export a variable to child process I believe you should do:

export var

Remark if you do: export $var you will export the value variable.

Once the variable is correctly exported to child process if you start Vim you can the its value with the $var syntax:

:echo $var
:echom 'var: ' .. $var
  • Ah, lmao, just a simple syntax error, thank you kinda stranger!
    – Ella H
    Commented Oct 6, 2023 at 17:42

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