Skip to content

Linux Terminal Shortcuts - GNU Readline

DescriptionShortcut
AutocompleteTAB
CUA: Cut word backward (behind cursor)C-w
CUA: Cut word forwardM-d
CUA: Paste, yank from kill ringC-y
CUA: Kill (to clipboard) to end of line/beginning of lineC-k, C-u
CUA: Cycle undo listC-_ , C-x, C-u, C-/
Clear terminal screenC-l
Cursor: delete everything to beginning of lineC-u
Cursor: delete everything to end of lineC-k
Cursor: line - move to beginningC-a, Home
Cursor: line - move to endC-e, End
Cursor: move to beginning of wordM-b / C-left arrow
Cursor: move to end of wordM-f / C-right arrow
Search history reverse isearchC-r
Transpose character / wordC-t / M-t
DescriptionShortcut
Start/stop macro recordsC-x (, C-x )
Play last macroC-x e
Print out macroC-x p (bound in .inputrc, default is unbound
DescriptionShortcut
Complete at pointTAB
List completionsM-?
Insert all completionsM-*
Complete tildeM-~
  • Use numeric arguments like Emacs
    • M-2 M-d to kill two words forward
DescriptionShortcut
Insert commentM-#
Clear screenC-c C-l
DescriptionCommand
Empty file without deleting itcat /dev/null > filename
Go to home directorycd or cd ~
List files in current directoryll (ls -l
Open Ubuntu files in folder (e.g. nautilus ~/)nautilus
Reuse entire last command (e.g. useful for sudo !!)!!
Reuse the last argument from the previous command (bash)!$
Reuse the last argument… example:ls tool && cd !$
Run multiple commands if previous command was successfulcommand1 && command2
Run multiple commands in one linecommand1; command2; command3
Stop a running commandC-c
Switch back to last working directorycd -
View a file in a paged fashionless filename
Watch log file for changetail -f logfile

GNU Readline and Emacs share many shortcuts

GNU Readline is reused by: bash, python, GDB, psql, sqlite, and more, allowing shortcuts to be used in those CLIs.

  • Keyboard macros
  • History search and navigation
  • Faster editing

You can record, play back, and print out keyboard macros. Can be written, no recording needed. Can be written on the fly.

Example use cases

  • apt-cache search emacs with keyboard macro transformed into $(apt-cache search emacs | ezf -f 1)
  • Wrap prompt to simple python commands like dir(…), help(…)
  • Readline’s kill ring (clipboard) is not shared with the system clipboard
  • It is not universally used, like Zsh and fish use their own line editing
    • Many commands are shared with fish; however macros may not function the same
  • Prompt undo history is reset on each new prompt
  • Global settings in /etc/inputrc
  • User settings in ~/.inputrc
  • Uses Emacs notation like C-x for ctrl + x and M-x for alt + x and chords like C-x p
    • Except in .inputrc , use \e for alt (meta) and \C for control.
  • Examples:
Terminal window
# Correct - binds to C-x q
"\C-xq": "Hello, World"
# Correct - binds to C-M-p
"\e\C-p": "Good Bye!"
# Set variables with set keyword
set expand-tilde on
# Limit settings to certain programs
$if Bash
# ...
$else
# ...
$endif
# By default the keyseq-timeout value is a rather ambitious 500 ms. I find that far too quick, so I change it 1200 ms:
set keyseq-timeout 1200
# Colored completion of partial matches in bash
# by default color highlighting for completition is disabled
set colored-stats on
set colored-completion-prefix on