← Back to articles

Terminal Keyboard Shortcuts

Path: Computer Tech/Terminal/Terminal Keyboard Shortcuts.mdUpdated: 2/3/2026

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

ShortcutActionWhy It Matters
Ctrl+AJump to start of lineFaster than holding ←
Ctrl+EJump to end of lineFaster than holding β†’
Option+←Move back one wordNavigate long commands quickly
Option+β†’Move forward one wordNavigate 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

ShortcutActionMemory Aid
Ctrl+WDelete word backward"Word back"
Ctrl+UDelete to start of line"Undo to start"
Ctrl+KDelete to end of line"Kill to end"
Option+BackspaceDelete word backwardLike Ctrl+W on Mac
Option+DDelete 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

ShortcutActionUse Case
Ctrl+TSwap last two charactersFix typos like "teh" β†’ "the"
Option+TSwap last two wordsFix word order mistakes
Ctrl+YPaste (yank) last deletionRecover deleted text
Ctrl+_Undo last editMade 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

ShortcutActionPower Move
Ctrl+RReverse history searchFind commands you ran weeks ago
Ctrl+GCancel reverse searchExit search without running
Ctrl+PPrevious commandSame as ↑
Ctrl+NNext commandSame as ↓
Option+.Insert last argumentReuse 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:

bash
brew install zsh
chsh -s /usr/local/bin/zsh  # or /opt/homebrew/bin/zsh on Apple Silicon

Complete Reference Table

CategoryShortcutAction
NavigationCtrl+AStart of line
Ctrl+EEnd of line
Option+←Back one word
Option+β†’Forward one word
DeletionCtrl+WDelete word back
Option+BackspaceDelete word back (Mac)
Option+DDelete word forward
Ctrl+UDelete to line start
Ctrl+KDelete to line end
EditCtrl+TSwap last 2 chars
Option+TSwap last 2 words
Ctrl+YPaste (yank)
Ctrl+_Undo
HistoryCtrl+RReverse search
Ctrl+GCancel search
Ctrl+PPrevious command
Ctrl+NNext command
Option+.Last argument
ProcessCtrl+CKill current process
Ctrl+DExit shell
Ctrl+ZSuspend process
Ctrl+LClear screen

Practice Exercise

Try editing this command using only keyboard shortcuts:

bash
docker run -it --rm -v $(pwd):/workspace --name mycontainer ubuntu:latest bash

Tasks:

  1. Change ubuntu:latest to node:18
  2. Change mycontainer to dev-env
  3. Delete the --name flag entirely
  4. Add -p 3000:3000 after --rm

Solutions:

  1. Option+← (twice to get to ubuntu), Ctrl+W, type node:18
  2. Option+← (several times), Ctrl+W, type dev-env
  3. Option+← to --name, Option+← Option+← to select both words, Ctrl+W Ctrl+W
  4. 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: