Terminal keyboard shortcuts

I've gathered some haxy stuff for the terminal since I tend to forget a lot of them.

Published: 2024-03-28
Last updated: 2025-02-15 18:31

linux
bash
terminal
shortcuts
cheat-sheet

>Shortcuts for emacs mode (set -o emacs)

>>Shortcuts

>>>History

Command Description
Ctrl+_ Undo last key press
Alt+< Go to start of history
Alt+> Go to end of history (current)
Ctrl+r Search backwards in history
Ctrl+s Search forwards in history (must use together with stty -ixon, see the general shell settings)
Ctrl+g Cancel search
Ctrl+o Run current command
Alt+r Revert any changes to a command you’ve pulled from your history if you’ve edited it.
Command Description
Ctrl+a Go to beginning of line
Ctrl+e Go to end of line
Ctrl+b Go backwards one character
Alt+b Go backwards one word
Ctrl+f Go forwards one character
Alt+f Go forwards one word
Ctrl+x, Ctrl+x Move between the beginning of the line and the current position of the cursor

>>>Capitalization

Command Description
Alt+u Capitalize every character from the cursor to the end of the current word, converting the characters to upper case.
Alt+l Uncapitalize every character from the cursor to the end of the current word, converting the characters to lower case.
Alt+c Capitalize the character under the cursor. Your cursor will move to the end of the current word.

>>>Editing

Command Description
Ctrl+d Delete the character under the cursor
Alt+d Delete the part of the word that starts at (and is after) the cursor
Ctrl+h Delete the character before the cursor
Alt+h Delete the part of the word that ends at (is before) the cursor

>>>Cut and paste

Command Description
Ctrl+w Cut the word before the cursor, adding it to the clipboard.
Ctrl+k Cut the part of the line after the cursor, adding it to the clipboard.
Ctrl+u Cut the part of the line before the cursor, adding it to the clipboard.
Ctrl+y Paste the last thing you cut from the clipboard. The y here stands for “yank”.

>Shortcuts for vi mode (set -o vi)

See [3].

>General shell settings

>>Ctrl+s behavior

stty -ixon # Make the terminal not stop when pressing Ctrl-s
stty ixany # Revert

>Sources:

[1] How to geek: Keyboard shortcuts for bash command shell […]
[2] Digital ocean: How to use bash history commands and expansion […]
[3] Catonmat: Bash VI editing mode cheat sheet