The question originally asked about a solution for bash. I answered before I discovered that it was subsequently changed to be all about zsh. Fortunately, that original answer is very similar to the answer for zsh. And because several people found value in that answer (based on their upvotes) I've decided to address both shells rather than totally overwrite the bash information.
The 'shell'
setting can be used to tell Vim how to start the shell used in terminal commands. The default value is the value of environment variable $SHELL
or, if that's not found, just sh
.
If you just set it to, say, /bin/zsh
your startup file won't be picked up. You can tell the shell which startup file to use with the --rcs
flag (bash: --rcfile
). Alternatively, if you specify -i
(for "interactive" shell) then the shell will read $ZDOTDIR/.zshrc
or $HOME/.zshrc
if ZDOTDIR
is not set (for bash it's always $HOME/.bashrc
). As it happens, you also need -i
if you want to pick up aliases so that makes the choice clear.
Putting it all together, you can add something like this to your vimrc file:
" zsh
let &shell='/bin/zsh -i'
" bash
let &shell='/bin/bash -i'
However, something strange happens with zsh (bash works fine). Vim gets put in the background and you are dropped at your zsh prompt with this message:
zsh: suspended (tty output) vim
The workaround I came up with is to defer the setting of 'shell'
by adding this to vimrc instead of the line above:
autocmd vimenter * let &shell='/bin/zsh -i'
Hopefully no other strange things happen but so far the testing I've done has gone well.