Emacs - readline library cheat sheet

Bash Emacs Editing Mode Cheat Sheet

Bash’s default editing mode is Emacs. Here’s a list of the most useful shortcuts to help you navigate and edit the command line efficiently.

Cursor Movement

CommandDescription
C-aMove to the beginning of the line
C-eMove to the end of the line
C-bMove backward one character
C-fMove forward one character
M-bMove backward one word
M-fMove forward one word
C-lClear screen and redisplay the line

Editing Text

CommandDescription
C-dDelete the character under the cursor
C-hDelete the character before the cursor
M-dDelete the word after the cursor
M-DELDelete the word before the cursor
C-kKill from cursor to end of line
C-uKill from cursor to beginning of line
C-wKill the word behind the cursor
M-tTranspose (swap) the last two words
C-tTranspose (swap) the last two characters
C-yYank (paste) the last killed text

Command History

CommandDescription
C-pPrevious command in history
C-nNext command in history
M-<Move to the first command in history
M->Move to the last command in history
C-rReverse search through history
C-sForward search through history (might be disabled in some terminals)

Miscellaneous

CommandDescription
C-_ or C-x C-uUndo the last editing command
C-x C-eEdit the current line in an external editor (usually vi or emacs)
M-&Run the previous command in the background
C-v or M-vInsert the next character typed literally (e.g., allows input of control characters)

Note: In this cheat sheet, C stands for the Control key and M stands for the Meta key (usually the Alt or Option key). Combining C or M with a character means pressing the Control or Meta key, respectively, while also pressing that character.


** If you want to check what else I'm currently doing, be sure to follow me on twitter @rderik or subscribe to the newsletter. If you want to send me a direct message, you can send it to derik@rderik.com.