Skip to main content

GNU Readline Keybindings Cheatsheet

GNU Readline is the input library used by bash, zsh, psql, python REPL, and many CLI tools. The default mode is Emacs mode (switch with set -o emacs; toggle to vi mode with set -o vi).

Movement

(| = cursor position)

ShortcutActionMnemonicBeforeAfter
Ctrl+AStart of lineA = beginninghello| world|hello world
Ctrl+EEnd of lineE = endinghello| worldhello world|
Ctrl+FForward one characterF = forwardhel|lo worldhell|o world
Ctrl+BBackward one characterB = backwardhell|o worldhel|lo world
Alt+FForward one wordF = far forwardhello |worldhello world|
Alt+BBackward one wordB = backhello |world|hello world
Ctrl+XXToggle cursor ↔ starthello| world|hello world

Comparison — Opposite Pairs

ForwardBackward
Ctrl+A — Start of lineCtrl+E — End of line
Ctrl+F — Forward one charCtrl+B — Backward one char
Alt+F — Forward one wordAlt+B — Backward one word

Comparison — Similar Pairs (Same Action)

KeybindingAlso Known As
Ctrl+XX — Toggle cursor ↔ startNo direct equivalent

Deletion

(| = cursor position)

ShortcutActionMnemonicBeforeAfter
Ctrl+WDelete word backwardW = Word backwardhello world| foohello |foo
Alt+DDelete word forwardD = forward (destreza/right)hello |world foohello |foo
Alt+BackspaceDelete word backward (same as Ctrl+W)hello world| foohello |foo
Ctrl+UDelete from cursor to start of lineU-turn backward to starthello world |foo|foo
Ctrl+KDelete from cursor to end of lineK = right side → delete righthello| world foohello|
Ctrl+DDelete char under cursor / EOFhell|o worldhel| world

Comparison — Opposite Pairs

Forward DeleteBackward Delete
Ctrl+D — Delete char forwardBackspace — Delete char backward
Alt+D — Delete word forwardCtrl+W / Alt+Backspace — Delete word backward
Ctrl+K — Delete to end of lineCtrl+U — Delete to start of line

Comparison — Similar Pairs (Same Action)

KeybindingAlso Known As
Alt+Backspace — Delete word backwardCtrl+W

Kill / Yank (Cut / Paste)

ShortcutAction
Ctrl+YYank (paste) the last killed text
Alt+YCycle through kill ring (after Ctrl+Y)

All deletion commands above "kill" (cut) into a ring buffer. Ctrl+Y pastes the most recent kill; Alt+Y cycles older entries.

History

ShortcutAction
Ctrl+P / Previous command
Ctrl+N / Next command
Ctrl+RIncremental search backward through history
Ctrl+SIncremental search forward (if enabled)
Alt+PNon-incremental search backward
Alt+NNon-incremental search forward
Alt+<First history entry
Alt+>Last history entry
Alt+.Insert last argument of previous command

Comparison — Opposite Pairs

Backward / PreviousForward / Next
Ctrl+P — Previous commandCtrl+N — Next command
Ctrl+R — Reverse searchCtrl+S — Forward search
Alt+P — Non-incremental backwardAlt+N — Non-incremental forward
Alt+< — First entryAlt+> — Last entry

Undo / Repeat

ShortcutAction
Ctrl+_ or Ctrl+X Ctrl+UUndo last edit
Alt+RUndo all changes on current line

Transpose (Swap)

ShortcutAction
Ctrl+TSwap two characters (char under cursor with char before it)
Alt+TSwap two words (word before cursor with word after)

Case Change

ShortcutAction
Alt+UUppercase next word (from cursor to end of word)
Alt+LLowercase next word
Alt+CCapitalize next word (first char uppercase, rest lowercase)

Macros

ShortcutAction
Ctrl+X (Start recording keyboard macro
Ctrl+X )Stop recording keyboard macro
Ctrl+X eExecute last recorded macro

Miscellaneous

ShortcutAction
Ctrl+LClear screen (same as clear)
Ctrl+X Ctrl+EOpen current line in $EDITOR
Alt+TabInsert completion (bash programmable completion)
Ctrl+ITab (same as Tab key)
Ctrl+MEnter (same as Enter key)

Numeric Argument Prefix

Press Alt+<N> before any command to repeat it N times.

ExampleResult
Alt+5 Alt+DDelete 5 words forward
Alt+10 Ctrl+FMove forward 10 characters
Alt+3 Ctrl+WDelete 3 words backward
Alt+100 Ctrl+BMove backward 100 characters

Official Reference