11

Is there a way to run my zshell aliases inside vim, with the output going to a new split?

I'm using oh-my-zsh's git aliases like gst, and I am unable to do :!gst inside vim.

Thanks

user2736286
  • 563
  • 6
  • 18

2 Answers2

7

Try

:set shell=zsh\ -l

And put the alias setting to ~/.zshenv

Here is the similar question terminal vim not loading .zshrc.

Community
  • 1
  • 1
Tim Green
  • 3,571
  • 2
  • 23
  • 23
  • In that link they just suggest `set shell=zsh\ -i`, which I tried, but it resulted in `suspended (tty output)` unfortunately. – user2736286 Feb 27 '14 at 01:44
  • @user2736286 get rid of the `-i` argument. This tells zsh to run as an interactive program which it is not (when run from inside vim). However the aliases might not be there depending on how your rc scripts are sourced... (I do not know zsh well enough to comment on if your aliases will be sourced in a non interactive shell) – FDinoff Feb 27 '14 at 02:08
  • Taking away the `-i` argument does not seem to work either. Maybe you are right about my rc scripts not being sourced, but unfortunately I am a beginner and have no idea how to check. – user2736286 Feb 27 '14 at 02:50
  • 4
    @user2736286 try to put alias in ~/.zshenv – Tim Green Feb 27 '14 at 02:51
  • @TimGreen Awesome, that worked! Please add it to your answer and I'll check it. Thanks – user2736286 Feb 27 '14 at 03:10
2

@tim-green is right!

As the man page says:

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.

Since you don't want interactive shell in vim (using ! at least), your only solution is to add (or source) your aliases inside ~/.zshenv.

As simple as that!

EDIT: no other modification is required, except to put:

set shell=/bin/zsh

in your vimrc.

Florian Klein
  • 8,692
  • 1
  • 32
  • 42