Bash Keyboard Shortcuts
readline shortcuts for moving around a line, cutting and yanking text, and reverse-searching your history. they work in bash and mostly in zsh too. you don’t need to memorize all of them — just pick a few and they’ll become muscle memory in like a week.
moving the cursor: Ctrl+A, Ctrl+E, Alt+F, Alt+B
Ctrl+A— jump to start of lineCtrl+E— jump to endAlt+F/Alt+B— move forward/back one word
I remapped caps lock to ctrl years ago and it made all of these way more comfortable. highly recommend.
cutting and pasting: Ctrl+W, Ctrl+U, Ctrl+K, Ctrl+Y
Ctrl+W— delete word before cursorCtrl+U— nuke everything before cursorCtrl+K— nuke everything after cursorCtrl+Y— paste back what you just nuked
the nice thing is these are actually cut operations, not delete. so Ctrl+U then Ctrl+Y is basically cut and paste. I use this when I start typing a command, realize I need to do something else first, Ctrl+U to stash it, do the other thing, then Ctrl+Y to bring it back.
Ctrl+R — reverse-searching your history
reverse search through your history. just start typing and it finds matching commands:
(reverse-i-search)`deploy': ./deploy.sh production
press Ctrl+R again to go further back. Enter to run it, Ctrl+G to bail out.
this replaces like 90% of what you’d use Bash History Expansion for honestly.
Alt+. — inserting the last argument of the previous command
inserts the last argument of the previous command. same as !$ but interactive — and if you keep pressing it, it cycles through older commands’ last args. super handy.
Ctrl+C, Ctrl+Z, Ctrl+D, Ctrl+L — controlling a running command
Ctrl+C— kill itCtrl+Z— suspend it (thenbgorfg, see Bash Process Tricks)Ctrl+D— EOF / close shellCtrl+L— clear screen
see also: Bash History Expansion, Bash Process Tricks, Bash Quick Loops
more shortcuts than you’ll ever need: catonmat readline cheat sheet