In my .zshrc
, I declare some aliases. Eg, which dbstart
shows the contents of that alias.
If I open vim from that shell, it is a child process. In Vim, I can run shell commands with :! some_command
. If I do :! echo $0
to see what shell Vim is using, it outputs '/bin/zsh'. However, my aliases are unavailable there.
How can I make my normal shell alises available when I shell out from Vim?
Two ideas:
- Somehow
EXPORT
the aliases from the original shell, to its child processvim
, and again to its shell child process - Configure Vim to read my
.zshrc
when creating its subshells
Best Answer
Old question, but the cleanest solution for vim in zsh was to add the alias to
~/.zshenv
, the file that zsh loads for all shells, login, interactive, or otherwise. This avoids starting vim or zsh with flags and any possible problems with that.There's a nice explanation of
~/.zshenv
vs~/.zshrc
here: http://tanguy.ortolo.eu/blog/article25/shrcBasically, zsh always sources
~/.zshenv
. Interactive shells source~/.zshrc
, and login shells source~/.zprofile
and~/.zlogin
. Thus, an interactive login shell sources~/.zshenv ~/.zprofile ~/.zlogin ~/.zlogin
, and a noninteractive, nonlogin shell like the one vim uses to run commands only sources~/.zshenv
.