C.W.K.
Stream
Lesson 09 of 10 · published

Keyboard Shortcuts: Readline & Zsh

~15 min · readline, shortcuts, emacs-keys, vi-mode

Level 0Window Tourist
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Why bother with shortcuts?

The shell isn't just a command runner — it's a text editor for your current line. Bash and zsh both use the Readline library (or zsh's own ZLE, which copies the same key bindings). Once you learn six or seven shortcuts, you stop reaching for the arrow keys and your hands stay on the home row.

Movement

  • Ctrl+A — start of line
  • Ctrl+E — end of line
  • Alt+B / Alt+F — back / forward one word
  • Ctrl+B / Ctrl+F — back / forward one char

Editing

  • Ctrl+W — delete previous word (most-used shortcut on the shell, full stop)
  • Ctrl+U — delete from cursor to start of line
  • Ctrl+K — delete from cursor to end of line
  • Ctrl+Y — paste the last killed text (the kill ring)
  • Ctrl+T — swap two adjacent characters

History

  • Ctrl+R — incremental reverse search; type characters, press Enter to run, Ctrl+R again for next match
  • Ctrl+P / Ctrl+N — previous / next history (same as up/down arrow)
  • !! — last command. sudo !! reruns the last command with sudo.
  • !$ — last argument of last command. Great for cat /long/path/to/log; vim !$.

Process control

  • Ctrl+C — interrupt the running command
  • Ctrl+Z — suspend it (restore later with fg)
  • Ctrl+D — EOF; exits the shell when the line is empty
  • Ctrl+L — clear screen (same as the clear command)

vi mode for ex-vim users

Run set -o vi (bash) or bindkey -v (zsh) to flip the prompt into modal editing. Esc to leave insert, then standard vim motion: w, b, 0, $, dd, cc. Pair with the next track's fzf integration and your prompt becomes a tiny vim.

Code

Practice the killers·bash
# Type a long command, then practice these:
echo 'this is a long sample command for practice'
# Press Ctrl+A (start), Ctrl+E (end)
# Ctrl+W to nuke the last word, Ctrl+U to nuke to start
# !! to rerun, sudo !! to rerun with sudo
Search history fast·bash
# Press Ctrl+R, type any substring of a previous command
# Press Ctrl+R again to walk earlier matches
# Press Enter to run, Esc/Ctrl+G to abort
# Or grep history directly
history | grep ssh

External links

Exercise

Type a long command but don't run it. Practice: Ctrl+A, Ctrl+E, Ctrl+W (repeat), Ctrl+U, Ctrl+Y. Then run a few commands and use Ctrl+R to find one. Add stty -ixon to .zshrc so Ctrl+S can't freeze you.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.