Readline Shortcuts Cheatsheet

These shortcuts are used on your unix command line prompt. They are done using the CONTROL (or CTRL) key on your keyboard. This is known historically as the “GNU readline library” or “GNU readline shortcuts”

Even though these shortcuts were implemented for Bash, they also work for ZShell.

Ctrl Key

All keyboards have a version of this key, typically in the lower-left position of the keyboard.

Below, you use the readline shortcut associated with CTRL by typing the CTRL key and the key indicated at the same time.

Alt or Meta Key

All unix prompts also have an ALT key, also known as a meta key. However, on your version of your shell, you may have to enable it or map it to one of the special keys on your keyboard.

For Mac OS using Terminal, there is no default META key — which means you cant’t use it until you specifically enable it in the Preferences. You switch this setting to use the Option key from the Terminal preferences. Click Profiles > choose the profile you want (you must do it for each profile here) > click Keyboard > Enable “Use Option as Meta Key”

  1. Open Terminal preferences, click Profiles
Open Terminal Preferences

2. Select a profile from the left, click Keyboard

Select keyboard in Terminal Preferences

3. Enable Use Option as Meta key

Now whenever you see Unix documentation that refers to an ALT key, you will use the Option key on your keyboard. If you leave this unchecked, you have no way to use the key in Terminal.

Be sure to set the editor for your shell.

The Readline Shortcuts

CTRL-amove the cursor to the beginning of line
CTRL-emove cursor to end of line
ALT-bmove the cursor back one word
ALT-Fmove cursor forward one word
CTRL-pgo back to the last shell command you executed
CTRL-fgo to the next shell command (assuming you used CTRL-p to see a pervious one)
CTRL-kCTRL-k is unix for kill, which means delete all of the text after the cursor. Adds to the shell clipboard, which is different than your operating system clipboard
CTRL-udelete (or “kill”) all of the text before the cursor. like with CTRL-K, this adds it to the unix clipboard.
CTRL-y“yank” (CTRL-y) is similar to what you know as “Paste” on your operating system. It will paste the clipboard (the unix clipboard, not the OS clipboard) to where the cursor currently is.
CTRL-rThis powerful feature lets you search the history of commands you have used on this shell prompt. Using an ‘i search,’ any suggestion for a previous command based on the commands you used in this same shell prompt will appear.