1

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

  • 1
    Instead of using an advertising search engine for hours, read the Z shell user manual. The information in M. Chazelas's answer is all in there, M. Chazelas even referring you directly to some of it, and can be found in a far shorter time than "hours". – JdeBP Apr 26 '18 at 17:48
  • Thanks for your advice :) I also find RTFM is quite worthwhile yesterday. – 陳 力 Apr 27 '18 at 3:39
4

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
  • 1
    There's no need to grep the output of bindkey. bindkey '^[x' also works. – JdeBP Apr 26 '18 at 17:50
  • @JdeBP, good point. See edit. – Stéphane Chazelas Apr 26 '18 at 18:48

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.