Don't understand german? Read or subscribe to my english-only feed.

mika’s advent calendar – day 4: zsh keybindings

If you want to become a Zsh poweruser you should make sure to effectively use keybindings.

First of all: use ‘bindkey -e’ to to enable emacs style or ‘bindkey -v’ for vi style. If you don’t know what you should prefer: use emacs style. Execute ‘bindkey’ to get a list of currently active key bindings in your Zsh.

A nifty feature we have in grml’s Zsh configuration is the insert-last-typed-word keybinding. If you don’t use grml’s Zsh configuration just execute:

insert-last-typed-word() { zle insert-last-word -- 0 -1 };
zle -N insert-last-typed-word;
bindkey "\em" insert-last-typed-word

Then pressing ‘Esc-m’ will insert the last typed word in your commandline. Give it a try and learn to love it. :)

Another must-know is edit-command-line (available in grml’s Zsh configuration by default as well):

autoload -U edit-command-line
zle -N edit-command-line
bindkey '\ee' edit-command-line

Press ‘Esc-e’ for editing the command line in $EDITOR.

Oh and please make me a favour and use ‘ctrl-d’ instead of executing ‘exit’. :)

4 Responses to “mika’s advent calendar – day 4: zsh keybindings”

  1. Simon Says:

    There really are a LOT of keybindings especially in emacs mode (and in vi mode things like insert-last-typed-word don’t work (in the grml config that is)).
    My actual question is: How do I use those keybindings that start with ^[….for example…
    “^[^?” backward-kill-word
    ctrl [ ctrl shift /
    srsly? How is that helping? :)

  2. mika Says:

    @simon: “^[” stands for escape, “^?” for delete/backspace


  3. lied Says:

    “Press ‘Esc-e’ for editing the command line in $EDITOR.”

    Hm, how can I go back to the command line and use the edited command?

  4. mika Says:

    @lied: just save and exit within your editor (‘:wq’ for Vim for example) :)