Similar to how to expand aliases inline in bash?

I'm using zsh 5.7.1 (x86_64-apple-darwin19.0) and Terminal 2.10 (433).

CTRL - ALT - E works for bash, what's the equivalent for zsh?

(If Use Option as Meta key is disabled in Terminal use ESC - CTRL - E)

CTRL - X - A is suggested but I can't make it work.


Just press C-x a, not C-x-a (C-x is a prefix). It will call _expand_alias function to expand the alias.

Moreover, you can add this line to your zshrc then you can expand alias just with TAB:

zstyle ':completion:*' completer _expand_alias _complete _ignored

A full example zshrc:

autoload -Uz compinit; compinit;
bindkey "^Xa" _expand_alias
zstyle ':completion:*' completer _expand_alias _complete _ignored
zstyle ':completion:*' regular true
  • I actually did try C-x a I typed it wrong in my description, the result is only a system bell. Also the line in zshrc doesn't do anything, for example alias pi="ssh root@" results in this when using TAB: pi piconv pidpersec.d pip pip3 pic piconv5.18 ping pip2 pip3.7 pico piconv5.28 ping6 pip2.7 pis – eethirteenzz Jan 5 '20 at 5:23
  • 1
    @eethirteenzz I have updated to answer. If still doesn't work. Check if _expand_alias function is defined and bindkey '^Xa' gives the right output. – Aloxaf Jan 5 '20 at 7:12
  • Cheers! I was expecting zsh alias expansion to work like bash without extras, is it standard on other systems? Also, what does autoload -Uz compinit; compinit; actually do? Together with bindkey "^Xa" _expand_alias I'm set. – eethirteenzz Jan 5 '20 at 14:16
  • 1
    1. Yes. In fact, autoload -Uz compinit; compinit; should be enough, it will automatically binds _expand_alias to C-x a(bindkey "^Xa" _expand_alias). 2. It loads and calls compinit function to initialize zsh's completion system, including making some keybindings. – Aloxaf Jan 5 '20 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.