Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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 process vim, and again to its shell child process
  • Configure Vim to read my .zshrc when creating its subshells
share|improve this question
include your .zshrc into .profile (which seems to be use by vim –  Kiwy Feb 4 '14 at 13:31

4 Answers 4

Looks like this works for zsh:

  • Ensure that $ZDOTDIR= the directory where .zshrc is located. Eg, export ZDOTDIR=$HOME
  • In .vimrc, set shell=zsh\ -i or set shellcmdflag+=i for the same effect.

The -i is because, when started in interactive mode, zshell loads $ZDOTDIR/.zshrc. See man zsh and search for $ZDOTDIR for details.

share|improve this answer
Hmmm, this creates a weird issue for me: copying to the system clipboard like "+y now suspends Vim!… –  Nathan Long Feb 4 '14 at 16:37
My vim becomes suspended as soon as I open it. –  Caleb Aug 13 at 17:26

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:

Basically, 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.

share|improve this answer
This is not a link-only answer, but it would be best if you inlined the explanation of the difference from the link; that way everyone can benefit from the explanation here and we are safe from linkrot. –  HalosGhost Apr 18 at 20:49
Updated my answer with the main points from the link. –  Kevin Lee Apr 22 at 0:31
This worked exponentially better for me than the other answers. When I added for vim to start an interactive shell, it suspended immediately. When I use the .zshenv file (which I previously didn't know existed), I got my aliases back! –  Caleb Aug 13 at 17:25

I believe when you're in vim and you use the :!some_command it's using whatever shell is defined by the environment variable $SHELL.

This is configurable, so you could change by overriding the $SHELL behavior in your $HOME/.vimrc file to use zsh instead.

:set shell
:set shell=zsh\ -i

Or in your .vimrc using 1 of these 2 lines

 set shell=/bin/bash\ -i
 set shell=/bin/zsh\ -i

Vim help

See :help shell from within vim for more info.

:!{cmd}                 Execute {cmd} with the shell.  See also the 'shell'
                        and 'shelltype' option.
                        Any '!' in {cmd} is replaced with the previous
                        external command (see also 'cpoptions').  But not when
                        there is a backslash before the '!', then that
                        backslash is removed.  Example: ":!ls" followed by
                        ":!echo ! \! \\!" executes "echo ls ! \!".
                        After the command has been executed, the timestamp of
                        the current file is checked timestamp.
share|improve this answer
No, as I said: "If I do :! echo $0 to see what shell Vim is using, it outputs '/bin/zsh'" –  Nathan Long Feb 4 '14 at 13:34
@NathanLong - no I think that's misleading you, see my updates. –  slm Feb 4 '14 at 13:36
@slm vim pulls the value from $SHELL. So your shell is /bin/bash. If my shell is /bin/zsh, thats what it'll use. –  Patrick Feb 4 '14 at 13:40
@Patrick - thanks, fixed. –  slm Feb 4 '14 at 13:58

By setting shell=/usr/bin/zsh\ -l in .vimrc solved my problem


I'm using: linux mint 17.1

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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