Why is an environmental variable not expanded in one of my machine but work on the other in Vim?

StackOverflow https://stackoverflow.com/questions/23310316

  •  09-07-2023
  •  | 
  •  

Question

I use two Macs and use the same ~/.vimrc file, which is stored at Dropbox, and add a symbolic link to it from within both computers at the same location, ~/.vimrc. So I don't think there is any difference whatsoever between the two computer's ~/.vimrc file.

However, when I try to call :tabnew $R from within one computer's MacVim application, the environmental variable is not expanded correctly. The command works on my other computer, and I set $R to ~/r in both of my Macs.

So what does prevent one from being expanded but nonetheless it works on the other? Even echo $R not working on the computer...

The official doc implies that I don't need to set any configuration to properly expand the environmental variable. Also, the environmental variable correctly is expanded in my Terminal.

Is there anything that I'm missing?

Was it helpful?

Solution 2

I finally got the reason it prevented environment variables from being expanded is that I switched to zsh shell, and it doesn't load those environment variables defined in ~/.zshrc when MacVim is launched. When I used bash shell, I defined all of those variables in ~/.bash_profile.

The solution is to define those variables in ~/.zshenv, not ~/.zshrc. I suspect that the MacVim is assumed to be launched as a shell script, and when a command is executed as a shell script in zsh, only ~/.zshenv is loaded.

OTHER TIPS

If even echo $R is not working, it means the environment variable R simply is not defined on that machine, so there's also nothing to expand in your .vimrc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top