19

My terminal vim configuration is not loading the ~/.zshrc. Zsh is the environment login shell. What is the proper configuration for this situation?

Here are some measures I've already taken and since removed:

set shell=zsh
(uses zsh as shell but doesn't source the rc)

set shellcmdflag=-ci
(all output suspended)

cat ~/.zshenv
$ source ~/.zshrc
(many errors when opening vim)

Matt Ryan
  • 1,717
  • 2
  • 20
  • 30

3 Answers3

12

The accepted answer doesn't work as expected. The actual solution should be putting the aliases and other ~/.zshrc content into ~/.zshenv. The only thing needed in ~/.vimrc is set shell=zsh without any flags.

Yulun
  • 204
  • 3
  • 11
  • the manual entry provides the insight you need to resolve the issue. my problem was related to the read order of commands. nowhere were aliases mentioned as being a problem. – Matt Ryan Jan 18 '16 at 03:54
  • 7
    A bit smoother. Add a symlink `ln -s ~/.zshrc ~/.zshenv ` – zhukovgreen Nov 15 '17 at 09:47
10

From the manual:

Commands  are  first  read from /etc/zshenv; this cannot be overridden.

[...]

Commands are then read from $ZDOTDIR/.zshenv. If the shell is a
login shell, commands are read from /etc/zprofile and then 
$ZDOTDIR/.zprofile. Then, if the shell is interactive, 
commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc. Finally,
if the shell is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are
read.

From what I understand,

set shell=zsh\ -i

should work.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • 3
    that's the second command in `set shellcmdflag=-ci`. when i try that, all the output is suspended. – Matt Ryan Jul 10 '12 at 17:39
  • `-ci` or `-i` are the correct flags. Do you mean that vim is suspended and you are at the shell's prompt? That's the expected and normal behaviour of Vim in a terminal. You won't be able to change it at all. In GVim/MacVim, doing `:!` expands the command-line into a sort of dumb terminal for you to read the output of ``. If that's the behaviour you are after you'll have to switch to GVim/MacVim. – romainl Jul 10 '12 at 18:54
  • 8
    With either the `ci` or `c` flags, commands finish with something like `21195 suspended (tty output) vim` and I am left at the zsh shell prompt. I then have to type `fg` to have the expected result. – nimser Oct 07 '13 at 08:27
  • @slm the manual entry provides the insight you need to resolve the issue. my problem was related to the read order of commands. – Matt Ryan Mar 26 '15 at 18:42
1

I found an handy solution. As the only thing I really need is all my aliases, I added a function to my ~/.zshrc file:

function zshalias()
{
  grep "^alias" ~/.zshrc > ~/.zshenv
}

Then execute source ~/.zshrc && zshalias.

In your vimrc you only need:

shell=zsh

Everything then works perfectly with no suspended tty output!