Emacs - readline library cheat sheet Oct 22 2023
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
1
2
3
4
5
6
7
8
9
10
11
| |---------------|-----------------------------------------|
| Command | Description |
|---------------|-----------------------------------------|
| C-a | Move to the beginning of the line |
| C-e | Move to the end of the line |
| C-b | Move backward one character |
| C-f | Move forward one character |
| M-b | Move backward one word |
| M-f | Move forward one word |
| C-l | Clear screen and redisplay the line |
|---------------|-----------------------------------------|
|
Editing Text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| |---------------|-----------------------------------------|
| Command | Description |
|---------------|-----------------------------------------|
| C-d | Delete the character under the cursor |
| C-h | Delete the character before the cursor |
| M-d | Delete the word after the cursor |
| M-DEL | Delete the word before the cursor |
| C-k | Kill from cursor to end of line |
| C-u | Kill from cursor to beginning of line |
| C-w | Kill the word behind the cursor |
| M-t | Transpose (swap) the last two words |
| C-t | Transpose (swap) the last two characters|
| C-y | Yank (paste) the last killed text |
|---------------|-----------------------------------------|
|
Command History
1
2
3
4
5
6
7
8
9
10
| |---------------|---------------------------------------------------------------------|
| Command | Description |
|---------------|---------------------------------------------------------------------|
| C-p | Previous command in history |
| C-n | Next command in history |
| M-< | Move to the first command in history |
| M-> | Move to the last command in history |
| C-r | Reverse search through history |
| C-s | Forward search through history (might be disabled in some terminals)|
|---------------|---------------------------------------------------------------------|
|
Miscellaneous
1
2
3
4
5
6
7
8
| |---------------|-------------------------------------------------------------------------------------|
| Command | Description |
|---------------|-------------------------------------------------------------------------------------|
| C-_ or C-x C-u| Undo the last editing command |
| C-x C-e | Edit the current line in an external editor (usually `vi` or `emacs`) |
| M-& | Run the previous command in the background |
| C-v or M-v | Insert 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.