-1

I just finished setting vim to use XDG variables (mostly taken from here), where:

XDG_CONFIG_HOME: ~/.config

XDG_CACHE_HOME: ~/.cache

When I launch MacVim from the terminal using mvim, everything specified in my vimrc is read.

However, when I open a file from the file manager (GUI), the vimrc is not read.

How do I ensure that GUI MacVim behaves like mvim?

Below in the Vim configuration in my .zshrc:

# Vim
export VIMINIT='source $MYVIMRC'
export MYVIMRC=$XDG_CONFIG_HOME/vim/vimrc
export VIMDOTDIR=$XDG_CONFIG_HOME/vim

More info:- ZSH is the default shell

There is a .zshenv file in $HOME with:

# ZSH
export ZDOTDIR="${ZDOTDIR:-$HOME/.config/zsh}"

# XDG compliant home directory
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_DATA_HOME="$HOME/.local/share"

The .zshrc is located in $HOME/.config/zsh

Saurabh
  • 5,176
  • 4
  • 32
  • 46

1 Answers1

1

Your environment variables are visible to mvim because they are set for the context in which it is executed.

Your environment variables are invisible to MacVim.app because they are not set for the context in which it is executed.

The most likely explanation is that zsh is not your system's login shell, so the commands in your ~/.zshrc are not executed when you log in, which makes your environment variables non-existing.

If that is the case and you want your environment variables to be global, you will have to either:

  • export them in the proper rc file of your login shell,
  • or tell your system to use zsh as your login shell.
romainl
  • 186,200
  • 21
  • 280
  • 313
  • I think she'll variables won't work in a GUI app like MacVim.app. See [this answer](https://apple.stackexchange.com/a/57402) for ideas how to set env variables for specific apps. – filbranden Dec 28 '20 at 16:49
  • 1
    This is one way to do it but environment variables work perfectly in GUI apps, specifically MacVim, if they are set in the login shell, @filbranden – romainl Dec 28 '20 at 18:39