Take the 2-minute tour ×
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 at 13:31
add comment

2 Answers

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! superuser.com/questions/712245/… –  Nathan Long Feb 4 at 16:37
add comment

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
shell=/bin/bash
: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 at 13:34
    
@NathanLong - no I think that's misleading you, see my updates. –  slm Feb 4 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 at 13:40
    
@Patrick - thanks, fixed. –  slm Feb 4 at 13:58
add comment

Your Answer

 
discard

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.