Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zshell aliases like !gst inside vim?

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

like image 859
user2736286 Avatar asked Feb 26 '14 23:02

user2736286


People also ask

What are zsh aliases?

Defining Aliases Aliases in zsh share the common alias builtin command from other shells. Aliases are handy for saving time when typing commands. If they are not "global aliases" then they only work at the beginning of a command prompt (more below). Typical aliases are used for commands such as: alias g=git.

Where should I put my aliases zsh?

zshrc file free of clutter. Place the aliases in their own file, ie: . zsh_aliases. You can also create a file for other things, like app shortcuts.

How do I add alias in zsh terminal?

To set up a simple alias, edit the ~/. zshrc file using your text editor and add an alias at the bottom. It is good to keep all your aliases in a single section of the file to avoid confusion and ease of edit. alias ginit="git init ."


2 Answers

@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.

like image 92
Florian Klein Avatar answered Sep 18 '22 20:09

Florian Klein


Try

:set shell=zsh\ -l

And put the alias setting to ~/.zshenv

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

like image 38
Tim Green Avatar answered Sep 21 '22 20:09

Tim Green