terminal vim not loading .zshrc
Asked Answered
P

3

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)

Plumose answered 10/7, 2012 at 14:22 Comment(0)
F
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.

Flabellum answered 10/7, 2012 at 14:56 Comment(4)
that's the second command in set shellcmdflag=-ci. when i try that, all the output is suspended.Plumose
-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 :!<command> expands the command-line into a sort of dumb terminal for you to read the output of <command>. If that's the behaviour you are after you'll have to switch to GVim/MacVim.Flabellum
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.Stubble
@slm the manual entry provides the insight you need to resolve the issue. my problem was related to the read order of commands.Plumose
S
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.

Stringhalt answered 2/12, 2015 at 17:57 Comment(2)
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.Plumose
A bit smoother. Add a symlink ln -s ~/.zshrc ~/.zshenv Teleplay
F
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.

Flabellum answered 10/7, 2012 at 14:56 Comment(4)
that's the second command in set shellcmdflag=-ci. when i try that, all the output is suspended.Plumose
-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 :!<command> expands the command-line into a sort of dumb terminal for you to read the output of <command>. If that's the behaviour you are after you'll have to switch to GVim/MacVim.Flabellum
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.Stubble
@slm the manual entry provides the insight you need to resolve the issue. my problem was related to the read order of commands.Plumose
U
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!

Uneven answered 10/2, 2018 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.