66

Where can I find a list of zsh commands that I can use with bindkey, with descriptions?

Each time that I look for name of some standard action (e.g., end-of-line), I need to google and guess that the command found is what I look for.

Related:

Community
  • 1
  • 1
Jakub M.
  • 32,471
  • 48
  • 110
  • 179

6 Answers6

86
  • bindkey -l will give you a list of existing keymap names.

  • bindkey -M <keymap> will list all the bindings in a given keymap.

  • If you use the zsh command line in emacs mode, then the emacs keymap is likely to be most important for you.

  • If you use it in vi mode, then you’d be interested in viins and vicmd.

(See the zshzle(1) man page for more details.)

Once you have a list of keybindings, you can search the official ZLE documentation for the name of the action (or “widget” in zsh parlance).

wjv
  • 2,288
  • 1
  • 18
  • 21
  • 13
    Also, executing `bindkey` with no arguments will print all keybindings. – Keith Hughitt Sep 16 '19 at 19:35
  • 5
    @KeithHughitt That is true, but only for the current keymap. Which may or may not be what you want. – wjv Sep 18 '19 at 07:01
  • Ah, good catch - I thought it was printing everything. Thanks for the clarifications! – Keith Hughitt Sep 18 '19 at 14:45
  • 2
    Actually my earlier comment wasn’t quite accurate either! Using `bindkey` without arguments will show the contents of the `main` keymap. `main` is an alias for either `emacs` or `viins`, depending on whether you’ve set up emacs- or vi-like line editing. The contents of `vicmd` can only be seen by using the `-M` flag. – wjv Sep 19 '19 at 06:30
48
zle -al

lists all registered zle commands

Dave Lee
  • 6,299
  • 1
  • 36
  • 36
  • Thanks, this was what I am looking for. – Kutsan Kaplan Sep 18 '17 at 02:32
  • 3
    This is a more exact answer of the original question than my answer above. Have an upvote! One could also mention that the list of standard widgets is available in the Zsh manual at: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#index-widgets_002c-standard – wjv Sep 18 '19 at 07:07
38

Commands available for use in the line editor are referred to as widgets. The standard widgets are listed in the zshzle manpage in the STANDARD WIDGETS section. That manpage is also available from the zsh website

qqx
  • 18,947
  • 4
  • 64
  • 68
  • I don't see any options in the "movement' section at that link that correspond to "page up" or "page down" behavior. Does zsh bindkey simply not offer that as a built-in option? – ely Jun 17 '23 at 19:28
  • @ely That seems more like a new question than a comment on this question+answer. What are you expecting for page up/down? If you're looking for something to scroll the displayed content, that would be a binding in your terminal, not something in zsh (or other shell). – qqx Jun 19 '23 at 20:21
14
  1. Zsh Line Editor Doc: https://web.cs.elte.hu/local/texinfo/zsh/zsh_10.html
  2. Look up system current bindkey setting: $ bindkey, eg($ bindkey|grep case, looking for down-case);
  3. $ zle -al used for list all registered zle commands;
  4. Bind your personal key for zsh command , $ vim ~/.zshrc, add
# bindkey
bindkey "^U"    backward-kill-line
bindkey "^u"    backward-kill-line
bindkey "^[l"   down-case-word
bindkey "^[L"   down-case-word

# alt+<- | alt+->
bindkey "^[f" forward-word
bindkey "^[b" backward-word

# ctrl+<- | ctrl+->
bindkey "^[[1;5D" backward-word
bindkey "^[[1;5C" forward-word
  1. See other things: oh-my-zsh down-case-word bug: https://github.com/robbyrussell/oh-my-zsh/commit/55a9d685fd960390a4f400ac461d901049a78beb
lupguo
  • 1,525
  • 13
  • 13
  • The official documentation for Zsh Line Editor is http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html; the link you refer to is only a copy maintained by some university in Hungary. – Franklin Yu Nov 25 '20 at 07:33
  • @lupguo how does one bind super/win key though? – MartinT Aug 18 '23 at 15:19
2

I'm on zsh via putty. For me the bindings were different. You can find this out with CTRL+V followed by for example the left arrow. It will display the used character sequence. So for me it was:

bindkey "^[[D" backward-word
bindkey "^[[C" forward-word
bindkey "^H" backward-kill-word
Goosebumps
  • 919
  • 2
  • 14
  • 27
  • The `read` command worked for me since I bound `ctrl+v` to paste: https://www.techrepublic.com/article/find-and-bind-key-sequences-in-bash/ – DharmaTurtle Jan 08 '22 at 20:49
1

After installing oh-my-zsh, I typed bindkey 'anything' then press tab, then say yes. The list of available bindkeys will be flushed out

Sang
  • 4,049
  • 3
  • 37
  • 47