Emacs Mode in Zsh

Jul 31, 2018  

Using Emacs Keybindings in Zsh

The default mode for typing in a Bash or Zsh shell is Emacs. It’s quite simple to update this to use Vim style bindings by entering bindkey -v in the shell, or by adding it to your .bashrc or .zshrc file. It can be canged back to Emacs mapping with bindkey -e.

However, we’re just going to take a quick look at the default bindings and make it just a bit easier to make quick ninja edits to the current command.

Shortcut Action
Movement
Ctrl + a Go to the start of the line
Ctrl + e Go to the end of the line
Hold Ctrl + x, x Jump between the beginning and the end of the line
Ctrl + b Go back one character
Ctrl + f Go forward one character
Alt + b Go back one word
Alt + f Go forward one word
Editing
Alt + Del Delete previous word
Alt + d Delete next word
Ctrl + w Cut the previous word
Ctrl + k Cut to the end of the line
Ctrl + u Cut to the beginning of the line
Ctrl + h Same as Backspace
Ctrl + d Same as Del
Alt + t Swap current and previous words
Ctrl + t Swap previous two characters
Escape + t Swap previous two words
Misc
Ctrl + y Paste (confusingly called “yank” from Emacs)
Alt + u Uppercase the rest of the word
Alt + l Lowercase the rest of the word
Ctrl + _ Undo
Ctrl + v Allow the next special character to be output to the terminal, e.g. Escape, Enter, or Tab

You may also review all of the key bindings by calling bindkey -M emacs