Must-Know Bash & Zsh Keyboard Shortcuts
Jun 30, 2026Many command-line shells (like Bash and Zsh) use the GNU Readline library to handle input. This means you have a powerful set of keyboard shortcuts at your disposal to edit, delete, and navigate long commands without using the arrow keys.
In this deep dive, we’ll cover standard shortcuts, how to enable Vim-style editing in your shell, and how to customize shortcuts using ~/.inputrc.
1. The Standard Emacs-Style Bindings (Default)
By default, most shells boot up in Emacs mode. These shortcuts work in almost every Unix terminal.
Cursor Navigation
Ctrl + a: Move the cursor to the beginning of the line.Ctrl + e: Move the cursor to the end of the line.Alt + f: Move the cursor forward by one word.Alt + b: Move the cursor backward by one word.Ctrl + xx: Toggle the cursor between the current position and the beginning of the line.
Editing & Deleting Text
Ctrl + u: Delete everything from the cursor to the beginning of the line.Ctrl + k: Delete everything from the cursor to the end of the line.Ctrl + w: Delete the word before the cursor.Alt + d: Delete the word after the cursor.Ctrl + y: Paste (yank) the text you just deleted withCtrl + u,Ctrl + k, orCtrl + w.Ctrl + _(orCtrl + xfollowed byCtrl + u): Undo your last edit.
History Navigation
Ctrl + r: Open interactive reverse search. Type characters to search back through your history, and pressCtrl + rrepeatedly to loop through matches. PressEnterto run the matched command.Ctrl + g: Exit history search mode without running any command.Alt + .(Alt + Period): Insert the last argument of the previous command. This is incredibly useful for creating a directory and then immediately changing into it:mkdir my_new_project cd [Press Alt + . here to insert "my_new_project"]
2. Going Modal: Enabling Vim Mode in the Shell
If you are a Vim or Neovim user, you can configure your shell to use Vim keybindings directly on the command line. This allows you to toggle between Insert Mode (for typing) and Normal Mode (for navigating, deleting, and editing using Vim keys).
In Bash:
To enable Vim editing mode in your current session:
set -o vi
To make this change permanent, add set -o vi to your ~/.bashrc file.
In Zsh:
To enable Vim editing mode in Zsh, add this to your ~/.zshrc:
bindkey -v
How it works:
- You start in Insert Mode (type commands normally).
- Press
Escto enter Normal Mode. - In Normal Mode, you can use:
h/lto move cursor left/right.w/bto jump forward/back by word.0/$to jump to start/end of line.i/ato enter Insert Mode before/after the cursor.ddto clear the entire command line.vto open the current command in your actual Vim editor (save and exit Vim to execute it).
3. Customizing Shortcuts with .inputrc
The GNU Readline library is configured via a file in your home directory called ~/.inputrc. You can use this file to bind custom key sequences to specific shell actions.
Here is a recommended ~/.inputrc configuration to supercharge your terminal:
# ~/.inputrc
# Enable case-insensitive tab completion
set completion-ignore-case on
# List completion matches immediately instead of double-tabbing
set show-all-if-ambiguous on
# Bind Up and Down arrow keys to search history matching what you already typed
"\e[A": history-search-backward
"\e[B": history-search-forward
# Bind Ctrl+Backspace to delete the previous word
"\e[3;5~": kill-word
To apply changes to .inputrc immediately without restarting your shell, run:
bind -f ~/.inputrc
Keybinding Quick Reference (Emacs Mode)
| Category | Shortcut | Description |
|---|---|---|
| Navigation | Ctrl + a |
Move cursor to beginning of line |
Ctrl + e |
Move cursor to end of line | |
Alt + b / f |
Move cursor backward / forward one word | |
| Deletion | Ctrl + u |
Delete from cursor to start of line |
Ctrl + k |
Delete from cursor to end of line | |
Ctrl + w |
Delete previous word | |
Alt + d |
Delete next word | |
| Recovery | Ctrl + y |
Paste last deleted snippet |
Ctrl + _ |
Undo last action | |
| History | Ctrl + r |
Search command history |
Alt + . |
Insert last argument of previous command |