Terminal Keyboard Shortcuts
Terminal Keyboard Shortcuts
Most developers use only a fraction of available terminal keyboard shortcuts. Mastering these will dramatically speed up your command-line workflow.
What Layer Do These Work On?
These shortcuts operate at the shell layer (zsh/bash), not the terminal emulator or tmux. They work in any terminal, on any system, because they're part of the readline/emacs keybinding standard.
See Dev Environment Stack for the full layer model.
Essential Shortcuts You Should Use Daily
Line Navigation
| Shortcut | Action | Why It Matters |
|---|---|---|
| Ctrl+A | Jump to start of line | Faster than holding β |
| Ctrl+E | Jump to end of line | Faster than holding β |
| Option+β | Move back one word | Navigate long commands quickly |
| Option+β | Move forward one word | Navigate long commands quickly |
Example:
bash# You typed this long command: docker run -it --rm -v $(pwd):/workspace myimage # Cursor is at end. You need to change 'myimage' # Instead of: β β β β β β β (14 presses) # Just do: Option+β (1 press!)
Deletion Shortcuts
| Shortcut | Action | Memory Aid |
|---|---|---|
| Ctrl+W | Delete word backward | "Word back" |
| Ctrl+U | Delete to start of line | "Undo to start" |
| Ctrl+K | Delete to end of line | "Kill to end" |
| Option+Backspace | Delete word backward | Like Ctrl+W on Mac |
| Option+D | Delete word forward | "Delete word" |
Example:
bash# You typed: git commit -m "fixed bug in authentication system" # You want to change the message # Instead of: Backspace Γ 35 # Just do: Ctrl+U (clears whole line) # Retype: git commit -m "add user authentication"
Editing Shortcuts
| Shortcut | Action | Use Case |
|---|---|---|
| Ctrl+T | Swap last two characters | Fix typos like "teh" β "the" |
| Option+T | Swap last two words | Fix word order mistakes |
| Ctrl+Y | Paste (yank) last deletion | Recover deleted text |
| Ctrl+_ | Undo last edit | Made a mistake? Undo it! |
Example:
bash# You typed: mv file.txt backup/ # Oops, order is wrong. Instead of retyping: Option+T # Swaps to: mv backup/ file.txt
History and Search
| Shortcut | Action | Power Move |
|---|---|---|
| Ctrl+R | Reverse history search | Find commands you ran weeks ago |
| Ctrl+G | Cancel reverse search | Exit search without running |
| Ctrl+P | Previous command | Same as β |
| Ctrl+N | Next command | Same as β |
| Option+. | Insert last argument | Reuse file paths |
Example:
bash# You ran this yesterday: docker exec -it mycontainer bash # Today you need it again # Instead of: β β β β β (searching forever) # Just do: Ctrl+R, type "docker exec", Enter
Power move with Option+.:
bash$ cat /very/long/path/to/config.yaml # Output shown... $ nvim Option+. # Expands to: nvim /very/long/path/to/config.yaml
Advanced Techniques
Kill Ring (Cut and Paste)
When you use Ctrl+W, Ctrl+U, or Ctrl+K, the deleted text goes into a "kill ring". You can paste it back with Ctrl+Y.
bash# Type a long path /Users/ntiruviluamala/Code/github.com/theslyprofessor/midimaze # Delete it Ctrl+U # Type a command cd # Paste the path back Ctrl+Y # Result: cd /Users/ntiruviluamala/Code/github.com/theslyprofessor/midimaze
Repeat Last Argument
bash$ mkdir new-project $ cd Option+. # Expands to: cd new-project
Transpose Characters for Typos
bash# You typed: gti status # Cursor is after "gti" Ctrl+T # Swaps to: git status
Mac-Specific Notes
Option Key Configuration
On Mac, you might need to configure your terminal to use Option as Meta key:
In Ghostty: Check terminal preferences In iTerm2: Preferences β Profiles β Keys β Left/Right Option key β Esc+
If Option+β inserts weird characters instead of moving by word, you need to enable this setting.
Homebrew Shell vs System Shell
macOS ships with old bash. Install modern zsh via Homebrew:
bashbrew install zsh chsh -s /usr/local/bin/zsh # or /opt/homebrew/bin/zsh on Apple Silicon
Complete Reference Table
| Category | Shortcut | Action |
|---|---|---|
| Navigation | Ctrl+A | Start of line |
| Ctrl+E | End of line | |
| Option+β | Back one word | |
| Option+β | Forward one word | |
| Deletion | Ctrl+W | Delete word back |
| Option+Backspace | Delete word back (Mac) | |
| Option+D | Delete word forward | |
| Ctrl+U | Delete to line start | |
| Ctrl+K | Delete to line end | |
| Edit | Ctrl+T | Swap last 2 chars |
| Option+T | Swap last 2 words | |
| Ctrl+Y | Paste (yank) | |
| Ctrl+_ | Undo | |
| History | Ctrl+R | Reverse search |
| Ctrl+G | Cancel search | |
| Ctrl+P | Previous command | |
| Ctrl+N | Next command | |
| Option+. | Last argument | |
| Process | Ctrl+C | Kill current process |
| Ctrl+D | Exit shell | |
| Ctrl+Z | Suspend process | |
| Ctrl+L | Clear screen |
Practice Exercise
Try editing this command using only keyboard shortcuts:
bashdocker run -it --rm -v $(pwd):/workspace --name mycontainer ubuntu:latest bash
Tasks:
- Change
ubuntu:latesttonode:18 - Change
mycontainertodev-env - Delete the
--nameflag entirely - Add
-p 3000:3000after--rm
Solutions:
- Option+β (twice to get to ubuntu), Ctrl+W, type
node:18 - Option+β (several times), Ctrl+W, type
dev-env - Option+β to
--name, Option+β Option+β to select both words, Ctrl+W Ctrl+W - Navigate to after
--rm, type-p 3000:3000
The key insight: With practice, you'll edit commands 3-5Γ faster than using arrow keys and backspace.
Related:
- Shell Line Editing with Zsh - Configure your shell
- Dev Environment Stack - Understanding the four layers
- tmux - Terminal Multiplexer - Multiplexer keybindings (different layer)