Bash
Shortcuts
These shortcuts are provided by the readline
library, so any shell using
readline
(e.g. Bash, zsh, etc) should provide these.
Terminology
M-<key>
- indicates a key combination with the Meta key- Meta is usually bound to the Alt key
- On macOS, the built-in Terminal program allows you to bind Meta to Option
C-<key>
- indicates a key combination with the Control key- Kill - delete text and put it in the kill ring
- Kill ring -
readline
's variant of a clipboard with multiple temporary buffers - Yank - paste the top of the kill ring at the cursor
Movement
M-f
- move forward one wordM-b
- move back one wordC-f
- move forward one characterC-b
- move back one characterC-a
- move to the start of the lineC-e
- move to the end of the line
Text editing
M-d
- kill one word forwardC-w
- kill one word backwardC-u
- kill from the cursor to the beginning of the lineC-k
- kill from the cursor to the end of the lineM-l
- make the word after the cursor lowercaseM-u
- make the word after the cursor uppercaseC-y
- yank the top of the kill ring after the cursorM-y
- if you've just yanked, use this to cycle through the kill ring
Numeric arguments
Most of Bash's movement and text editing commands take a numeric argument to
repeat the command that many times. You issue the numeric argument before the
command with M-<n>
, where <n>
is a number.
Examples:
M-2 M-d
- kill two words forwardM-3 C-w
- kill three words backward
You can also supply a negative argument to most commands that operate forward
or backward, which will reverse the direction of the command. I've never found
that very useful, but it's neat to understand what happens when you accidentaly
combine Meta and -
.
M-(-) 2 M-d
- kill two words backward
It's also possible to just repeat characters.
M-50 b
- repeat the characterb
50 times