# Bash Keyboard Shortcuts

[readline](https://tiswww.case.edu/php/chet/readline/rltop.html) 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 line
- `Ctrl+E` — jump to end
- `Alt+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 cursor
- `Ctrl+U` — nuke everything before cursor
- `Ctrl+K` — nuke everything after cursor
- `Ctrl+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](/articles/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 it
- `Ctrl+Z` — suspend it (then `bg` or `fg`, see [Bash Process Tricks](/articles/bash-process-tricks))
- `Ctrl+D` — EOF / close shell
- `Ctrl+L` — clear screen

---

see also: [Bash History Expansion](/articles/bash-history-expansion), [Bash Process Tricks](/articles/bash-process-tricks), [Bash Quick Loops](/articles/bash-quick-loops)

more shortcuts than you'll ever need: [catonmat readline cheat sheet](https://catonmat.net/bash-emacs-editing-mode-cheat-sheet)
