Skip to main content

GNU Readline

Last updated: 5 Aug 2020 ·
Posted in wiki#notes

vi mode

Entering input mode

ShortcutCommand
iInsert before cursor
aInsert after cursor
IInsert at the beginning of line
AInsert at the end of line
c<movement command>Change text of a movement command
C or c$Change text to the end of line
cc or S or 0c$Change current line
s or c[SPACE]Delete a single character under the cursor and enter input mode
rReplace a single character under the cursor(without leaving the command mode)
RReplace characters under the cursor
vEdit(and execute) the current command in a text editor(an editor in VISUALandVISUAL and EDITOR variables or vi)

Moving

ShortcutCommand
l or SPACEMove one character right
hMove one character left
wMove one word/token right
bMove one word/token left
WMove one non-blank word right
BMove one non-blank word left
eMove to the end of the current word
EMove to the end of the current non-blank word
0Move to the beginning of line
ˆMove to the first non-blank character of line
$Move to the end of line
%Move to the corresponding opening/closing bracket

Searching

ShortcutCommand
fcMove right to the next occurance of c
FcMove left to the previous occurance of c
tcMove right to the next occurance of c, then one char backward
TcMove left to the previous occurance of c, then one char forward
;Redo the last character finding command
,Redo the last character finding command in opposite direction

Deleting

ShortcutCommand
xDelete a single character under the cursor
XDelete a character before the cursor
d<movement command>Delete text of a movement command
D or d$Delete to the end of the line
dd or 0d$Delete current line
Ctrl-wDelete the previous word
Ctrl-uDelete from the cursor to the beginning of line

Undo/Redo

ShortcutCommand
uUndo previous text modification.
UUndo all previous text modifications on the line.
.Redo the last text modification.

Yanking and pasting

ShortcutCommand
y<movement command>Yank a movement into buffer
yyYank the whole line
pInsert the yanked text at the cursor
PInsert the yanked text before the cursor

History

ShortcutCommand
kMove backward one command in history
jMove forward one command in history
GMove to the history line n (you may specify the argument n by typing it on number keys, for example, 15G)
/string or Ctrl-rSearch history backward for a command matching string
?string or Ctrl-sSearch history forward for a command matching string (remember that on most machines Ctrl-s stops the output to the terminal (Ctrl-q starts output) and you
nRepeat search in the same direction as previous
NRepeat search in the opposite direction as previous

Completing

ShortcutCommand
TAB or Ctrl-i or =List possible completions
-Insert all possible completions

Misc

ShortcutCommand
Invert the case of the character under cursor, and move a character right
#Prepend # (comment character) to the line and send it to the history list
_Inserts the n-th word of the previous command in the current line
0, 1, 2, ...Sets the numeric argument
Ctrl-vInsert a character literally (quoted insert)
Ctrl-tTranspose (exchange) two characters

Emacs mode

Moving

ShortcutCommand
Ctrl-aMove to the start of the current line
Ctrl-eMove to the end of the line
Ctrl-fMove forward a character
Ctrl-bMove back a character
Alt-fMove forward to the end of the next word Words are alphanumeric
Alt-bMove back to the start of the current/previous word Words are alphanumeric
Ctrl-lClear the screen

History

ShortcutCommand
Ctrl-pFetch the previous command from the history list
Ctrl-nFetch the next command from the history list
Alt-<Move to the first line in the history
Alt->Move to the last line in the history
Ctrl-rSearch backward through history
Ctrl-sSearch forward through history
Alt-pSearch backward through history for a given string
Alt-nSearch forward through history for a given string
Ctrl-Alt-yInsert the first argument to the previous command With an argument n, insert the nth word from the previous command
Alt-. or Alt-_Insert the last argument to the previous command With an argument n, insert the nth word from the previous command

Changing text

ShortcutCommand
Ctrl-dDelete the character under the cursor
DeleteDelete the character before the cursor
Ctrl-v/Ctrl-qAdd the next character you type verbatim
Ctrl-tTranspose characters
Alt-tTranspose words
Alt-uUppercase the current word
Alt-lLowercase the current word
Alt-cCapitalize the current word

Killing and yanking

ShortcutCommand
Ctrl-kKill (cut) forwards to the end of the line
Ctrl-u or Ctrl-x/DeleteKill (cut) backwards to the start of the line
Alt-dKill (cut) forwards to the end of the current word
Alt-Delete or Ctrl-wKill (cut) backwards to the start of the current word
Alt-\Delete whitespace around the cursor
Ctrl-yYank (paste) the top of the kill ring
Alt-yRotate the kill ring, and yank (paste) the new top. Only works after a yank

Completing

ShortcutCommand
TABAutocomplete.
Alt-?List possible completions.
Alt-*Insert possible completions.

Macros

ShortcutCommand
Ctrl-x (Begin saving the characters typed as a macro.
Ctrl-x )Stop saving the characters typed as a macro.
Ctrl-x eExecute the most recent macro.

Misc

ShortcutCommand
Ctrl-x or Ctrl-rRead in the contents of the inputrc file.
Ctrl-gAbort current editing command.
Ctrl-_ or Ctrl-x or Ctrl-uIncremental undo, separately remembered for each line.
Alt-rUndo all changes made to this line. This is like executing the undo command enough times to return the line to its initial state.
Alt-Space or Ctrl-@Set the mark (save this location).
Ctrl-x or Ctrl-xSet the mark and jump to the previous mark.
Ctrl-]Search forwards for a single character in the current line and jump to that location.
Ctrl-Alt-]Search backwards for a single character in the current line and jump to that location.
Alt-#Comment the current line and start a new one.
Ctrl-eEnter Emacs editing mode.
Ctrl-Alt-jEnter Vi editing mode.