readline shortcuts

I used these 3 “shell” shortcut for a while without knowing what they were :

  • ctrl+r to search
  • ctrl+a to go at the start of the line
  • ctrl+e to go at the end.

I never gave it a though really, I just assumed they were bash/shell shortcut until I found this :

set -o vi

The default edition mode in a shell is aligned with the shortcuts of Emacs, and the option above switch to vi-mode shortcuts. What can I have out of the box with the Emacs shortcuts ? Here is my short selection :

  • alt+b: go backward one word at a time (b ackward)
  • alt+f: go forward one word at a time (f orward)
  • ctrl+w: delete previous word (w ord)
  • alt+d: delete next word (d elete)
  • ctrl+j: stop a search and keep the result (j ump to result)
  • ctrl+u: delete left hand side of a line (u ndo)
  • ctrl+k: delete right hand side of a line (k ill)
  • ctrl+l: clear screen (c l ear)

This shortcuts are handled not by bash but by a program called readline. It is used as an edit and history tool for cli interfaces. The python shell for instance uses readline too.

You can find more of these shortcuts here or by searching for readline shortcuts.

Avatar
Julien Pericat
Linux Sysadmin, SysOps & DevOps friendly

Happily automating and putting things in containers.

Related