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’. :)
December 4th, 2008 at 19:06
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? :)
December 5th, 2008 at 00:12
@simon: “^[” stands for escape, “^?” for delete/backspace
regards,
-mika-
December 8th, 2008 at 20:26
“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?
December 8th, 2008 at 22:07
@lied: just save and exit within your editor (‘:wq’ for Vim for example) :)
regards,
-mika-