Regarding Alt+x in zsh and how to bind Alt+x to something else

zsh

When I type Alt-x, execute: will pop up:

~ % 
execute: _

And I can continue type(space has no effect):

~ %        
execute: what'sthis

Q1: what's this promotion for?

Q2: How can i modify this shortcut to other key-binding? Because M-x in emacs is quite useful, and i use shell in emacs often, so the two conflict.

I have google for hours, but still have no answers(maybe my keywords are not correct–google: "zsh" + "excute:", "google: zsh keybinding bindkey

Best Answer

If you do:

bindkey | grep -F '^[x'

or simply:

bindkey '^[x'

or if in doubt about how to express Alt+x:

bindkey | grep -w x

You'll see:

"^[x" execute-named-cmd

That's the name of the widget bound to ESC x and most terminals send the ESC x character sequence upon pressing Alt+x

info zsh execute-named-cmd

Will tell you what that widget does (you may need to install the zsh-doc package on some systems).

As the name suggests, it prompts for a command to execute. Commands here being zsh widgets, editor commands. That's the equivalent of emacs' Meta-x, except that it's zsh editor commands instead of emacs command (the command is called execute-extended-command in emacs)

For instance, if at that prompt, you type backward-delete-char and press Return, it will invoke that widget which by default is bound to Backspace. You can do exactly the same in emacs.

If instead, you type descTab (Tab for completing it into describe-key-briefly, a widget not bound to any key by default, and also found in emacs) and press Return, you'll see another prompt:

$
Describe key briefly: _

Where you can press, say, Alt+x to see what that's bound do. You'd then get:

"^[x" is execute-named-cmd

If you do the same in emacs, you'll see:

M-x runs the command execute-extended-command

To see the list of widgets, run zle -al, zle -l for the non-builtin ones, bindkey to list the key bindings.

You can bind Alt+x to something else with

bindkey "^[x" some-widget
Related Question