Terminal Shortcuts: Readline Keybindings You Need

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.

Lina: Linny-senpai, when I need to move the cursor in the middle of a command, I just mash the arrow keys. It's so slow...
Linny-senpai: A shortcut does that instantly. And here's the thing: that shortcut isn't a bash feature.
Lina: Not a bash feature?
Linny-senpai: Right. The part that types, deletes, and moves the cursor on the command line is handled by a shared component called Readline. It's also known as a line-editing library — it takes care of everything for that one line of input. bash and most zsh setups both inherit these key bindings as-is.
Lina: So once I learn them, I can use them in lots of places.
Linny-senpai: Exactly. The keys you learn today still work on a server you reach over SSH (a way to log in to another computer remotely). Learn them once, and they're yours for good.

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+A jumps to the start of the line. Ctrl+E jumps to the end. No more mashing arrow keys to fix the front of a long command.

Lina: What should I learn first?
Linny-senpai: Cursor movement gives you the biggest win. Say you forgot sudo at the front of a long command. Ctrl+A snaps you to the start in one stroke.
Lina: How do I remember A?
Linny-senpai: Think of A as the line's Ahead (start) and E as its End. Try typing a longish command, but don't press Enter yet.
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+U deletes everything before the cursor. Ctrl+K deletes everything after. Ctrl+W deletes the previous word. You can retire the Backspace key.

Lina: When I mistype a command, I just hold down Backspace until it's all gone...
Linny-senpai: Let's retire that habit. Start with Ctrl+U. It clears everything before the cursor in one press.
Lina: So, once I meant to delete just one word in the middle of typing a long command, but I hit Ctrl+U by mistake instead. Everything I'd typed vanished. I panicked...
Linny-senpai: That's a classic slip. When the cursor sits at the end of the line, Ctrl+U deletes "everything you've typed so far" — the whole thing.
Lina: Oh, that makes sense now...! So if I only want to delete one word, I should use a different key?
Linny-senpai: Right. For just the word before the cursor, use Ctrl+W. Here, a "word" means a chunk separated by spaces.
Lina: What happens with a path like /home/lina/Documents?
Linny-senpai: A path has no spaces in it. So it counts as one chunk, and the whole thing gets deleted. It doesn't delete "one directoryA container that organizes files. Same idea as a "folder" on Windows or macOS. level at a time" for each / — keep that in mind.
Lina: What if I really do want to clear the whole line?
Linny-senpai: Press Ctrl+A to jump to the start, then Ctrl+K — that clears everything for sure. Ctrl+U at the very start of the line does nothing, by the way, since there's nothing before the cursor to delete.
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+R searches your history in reverse. Type part of a keyword and recall a long past command instantly.

Lina: That long docker command from yesterday — do I really have to type the whole thing again?
Linny-senpai: That's what Ctrl+R is for. It's history search: it finds past commands by keyword. Press Ctrl+R, then type part of the command, like docker.
Lina: Oh! Yesterday's command popped right up!
Linny-senpai: See? Press Enter to run it as-is. Press Ctrl+R again for an older match. Or use the arrow keys / Ctrl+E to edit it before running. To bail out, press Ctrl+G or Ctrl+C.
(reverse-i-search)`docker': docker compose up -d --build

The Ctrl+R flow

  1. Press Ctrl+R (the promptA symbol (like $ or #) shown when the shell is waiting for your input. shows (reverse-i-search))
  2. Type part of the command (partial matches appear)
  3. Press Ctrl+R again for older matches
  4. Enter to run / Ctrl+G to 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+L clears the screen. Ctrl+C interrupts a running command. Ctrl+D signals end of input. These are your escape hatches when things feel stuck.

Lina: When the screen fills up with output and gets hard to read, what do I do?
Linny-senpai: 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.
Lina: Actually, once I thought a command was frozen, so I pressed Ctrl+D. My whole terminal closed instead, and I panicked...
Linny-senpai: That's a common mix-up. Ctrl+D signals "I'm done typing" — it has no effect on a command that's already running.
Lina: I really thought it was the "stop" key...!
Linny-senpai: Here's a simple rule. Want to stop something? 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.

Lina: There are so many. I can't decide where to start.
Linny-senpai: Start with five. Work down the table below and consciously use them in today's terminal work. Within a week your fingers will move on their own.
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

Lina: I want to actually try what I learned!
Linny-senpai: Good. Let's try these three in a real terminal. Give each one a shot yourself before you check the answer.

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+E jump to the line start and end instantly
  • Ctrl+U / Ctrl+K / Ctrl+W delete input in bulk, and Ctrl+Y pastes it back
  • Ctrl+U clears everything before the cursor — watch out, it can delete more than you expect depending on cursor position
  • Ctrl+R searches past commands by keyword so you can reuse them
  • Ctrl+L (clear), Ctrl+C (interrupt), and Ctrl+D (end input) are good to know
  • Start with just five, and learn by using them

Next Reading

Share this article

Next steps