Terminal Shortcuts: Readline Keybindings You Need
What you'll be able to do
- Speed up the terminal with shortcuts like Ctrl+A and Ctrl+R
- Recall commands you typed before, quickly
Prerequisites (read these first)
Your Terminal Can Be Much Faster
You mistype a command, and there you go again, mashing the arrow keys to crawl back. Just moving the cursor back and forth eats up time. Retyping that long command you ran a minute ago is just as much of a hassle.
These quietly slow moves disappear once you learn a handful of shortcuts (keybindings: fixed key combinations that trigger an action).
In this guide, Lina and Linny-senpai walk through the Readline shortcuts that speed up terminalAn interactive program that reads the commands you type and runs them. input. The same keys work in both bash and zsh (bash and zsh are both shells — the program that takes the commands you type and runs them).
What You'll Learn
- That these shortcuts come from a library called Readline
- How to jump to the start or end of a line instantly (Ctrl+A / Ctrl+E)
- How to delete input in bulk (Ctrl+U / Ctrl+K / Ctrl+W)
- How to search and reuse past commands with Ctrl+R
- A short cheat sheet you can start using today
- A hands-on mini exercise to lock in what you learned
1. Where Do These Shortcuts Come From?
Conclusion: Shortcuts like Ctrl+A are not bash-specific. They come from Readline, a line-editing library. That's why they work across many shells.
Readline is the "line editor"
Readline manages that single line of command text: entering it, editing it, recalling it from history. By default it uses Emacs-style key bindings, which is why so many shortcuts use Ctrl.
2. Jump to Line Start or End Instantly
Conclusion:
Ctrl+Ajumps to the start of the line.Ctrl+Ejumps to the end. No more mashing arrow keys to fix the front of a long command.
sudo at the front of a long command. Ctrl+A snaps you to the start in one stroke.echo this is an example of a very long command
| Key | Action | Memory hook |
|---|---|---|
Ctrl+A |
Move to line start | Ahead (start) |
Ctrl+E |
Move to line end | End |
Ctrl+F |
One char right | Forward |
Ctrl+B |
One char left | Backward |
Alt+F |
One word right | Forward word |
Alt+B |
One word left | Backward word |
Arrow keys are fine for single characters. But learning the word-wise jumps Alt+F / Alt+B cuts the number of keystrokes it takes to fix a pathA string that describes the location of a file or directory. or an option.
On macOS's default Terminal app, the Alt (Option) key sometimes doesn't work out of the box. If that happens, press Esc and then F for the same effect.
3. How to Delete Mistakes in Bulk
Conclusion:
Ctrl+Udeletes everything before the cursor.Ctrl+Kdeletes everything after.Ctrl+Wdeletes the previous word. You can retire the Backspace key.
/home/lina/Documents?/ — keep that in mind.| Key | Action |
|---|---|
Ctrl+U |
Delete everything before the cursor |
Ctrl+K |
Delete everything after the cursor |
Ctrl+W |
Delete the word (chunk separated by spaces) before the cursor |
Ctrl+Y |
Paste back what you just deleted |
How much Ctrl+U deletes depends on your shell
In bash, Ctrl+U only deletes what's before the cursor. In zsh's default configuration, it deletes the entire line regardless of cursor position. Try it once on a short input first, and see for yourself how much gets deleted.
Cut and paste are a pair
Text removed with Ctrl+U / Ctrl+K / Ctrl+W is stored in a buffer called the "kill ring." Ctrl+Y (Yank) pastes it right back. Delete something by mistake? No need to panic.
4. How to Reuse a Command You Already Ran
Conclusion:
Ctrl+Rsearches your history in reverse. Type part of a keyword and recall a long past command instantly.
docker command from yesterday — do I really have to type the whole thing again?Ctrl+R, then type part of the command, like docker.(reverse-i-search)`docker': docker compose up -d --build
The Ctrl+R flow
- Press
Ctrl+R(the promptA symbol (like $ or #) shown when the shell is waiting for your input. shows(reverse-i-search)) - Type part of the command (partial matches appear)
- Press
Ctrl+Ragain for older matches Enterto run /Ctrl+Gto cancel
The up/down arrows, or Ctrl+P (Previous) / Ctrl+N (Next), step through history one command at a time. When you just want to tweak the last command, this is quicker.
5. Resetting the Screen and Your Input
Conclusion:
Ctrl+Lclears the screen.Ctrl+Cinterrupts a running command.Ctrl+Dsignals end of input. These are your escape hatches when things feel stuck.
Ctrl+L wipes it clean instantly. It's the same as the clear command, but faster than typing it. And if a command seems frozen and won't finish, Ctrl+C interrupts it.Ctrl+D. My whole terminal closed instead, and I panicked...Ctrl+D signals "I'm done typing" — it has no effect on a command that's already running.Ctrl+C. Have nothing more to type? Ctrl+D. On an empty prompt, Ctrl+D logs you out (the shell exits). You also use it to finish input when, say, cat is waiting for you to type.| Key | Action |
|---|---|
Ctrl+L |
Clear the screen (like clear) |
Ctrl+C |
Interrupt the running command |
Ctrl+D |
End of input / exit the shell on empty prompt |
Ctrl+C and Ctrl+D do different jobs. Ctrl+C means "stop what's running now." Ctrl+D means "I'm done typing." If something looks frozen, try Ctrl+C first.
6. The Shortcuts to Learn First
Conclusion: You don't need all of them at once. Drill just five — line start/end, line delete, and history search. That alone cuts the time each command takes to type.
| Priority | Key | Action |
|---|---|---|
| 1 | Ctrl+A |
Move to line start |
| 2 | Ctrl+E |
Move to line end |
| 3 | Ctrl+U |
Delete everything before cursor |
| 4 | Ctrl+R |
Reverse-search command history |
| 5 | Ctrl+L |
Clear the screen |
Shortcuts stick only when you use them on real commands. Try them hands-on over at How to Use the Terminal.
7. Mini Exercises - Try It Yourself
Task 1: Type a longish command (don't press Enter yet), then jump the cursor to the start and the end of the line as fast as you can.
Show Hint 1 (Direction)
You don't need to mash the arrow keys. One key press can jump straight to either end of the line.
Show Hint 2 (Key Names)
Use Ctrl+A for the start of the line and Ctrl+E for the end.
Show the Answer
Type a longish command with echo (don't press Enter yet). Ctrl+A jumps the cursor to the start of the line. Ctrl+E jumps it to the end. Both happen instantly.
Task 2: Place the cursor in the middle of a typed command, then delete "just what's before it" and "just what's after it" separately.
Show Hint 1 (Direction)
Instead of holding Backspace, there are dedicated keys that clear everything before the cursor, and everything after it, in one press each.
Show Hint 2 (Key Names)
Ctrl+U deletes before the cursor. Ctrl+K deletes after it.
Show the Answer
With the cursor in the middle of a command, Ctrl+U deletes everything before it. Ctrl+K (same position) deletes everything after it. Ctrl+Y pastes the deleted text back.
Task 3: Recall a command you typed earlier using history search.
Show Hint 1 (Direction)
You don't need to remember the whole command. One key lets you find a past command just by typing a fragment of it.
Show Hint 2 (Key Names)
Press Ctrl+R, then type part of the command.
Show the Answer
Press Ctrl+R and the prompt shows (reverse-i-search). Type part of the command (for example, echo), and a matching past command appears. Press Enter to run it, or Ctrl+G to cancel.
Summary
- These Ctrl shortcuts come from the Readline library, so they work in both bash and zsh
Ctrl+A/Ctrl+Ejump to the line start and end instantlyCtrl+U/Ctrl+K/Ctrl+Wdelete input in bulk, andCtrl+Ypastes it backCtrl+Uclears everything before the cursor — watch out, it can delete more than you expect depending on cursor positionCtrl+Rsearches past commands by keyword so you can reuse themCtrl+L(clear),Ctrl+C(interrupt), andCtrl+D(end input) are good to know- Start with just five, and learn by using them