READLINE(3)
π READLINE(3) Β· Library Functions Manual π
Okay bestie, welcome to readline(3), the library functions manual page π§
π NAME π
readline β get a line from a user with editing β¨
π¦ SYNOPSIS π¦
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
char *
readline (const char *prompt);
π COPYRIGHT π
Readline is Copyright (C) 1989-2025 Free Software Foundation, Inc. π«Ά
πΈ DESCRIPTION πΈ
okay so readline reads a line from the terminal and returns it π
It uses prompt as a prompt. If prompt is NULL or the empty string, readline does not issue a prompt π The line it hands back is allocated with malloc(3), so YOU are the one who has to free it when you're done π§Ή The returned line has the final newline removed, so only the text of the line is left β¨ Also, it's possible to type characters while quoting them so they skip any readline editing function they'd normally have, which means this line can contain embedded newlines and other special characters π wild, I know π
readline gives you editing powers while the user is typing the line π₯ By default the editing commands are similar to the ones in emacs, and there's also a vi-style editing interface if that's more your vibe π
This manual page only covers the most basic use of readline π· there is SO much more functionality, so check out The GNU Readline Library and The GNU History Library for the deets π
π RETURN VALUE π
readline returns the text of the line it read β¨ A blank line gives back the empty string π«§ If EOF shows up while reading a line and that line is empty, readline returns NULL π If EOF is read with a non-empty line, it gets treated as a newline, so no drama π
π NOTATION π
This section uses Emacs-style editing concepts and that notation for keystrokes, so pay attention, it's giving nerdy but it's cute π€ Control keys are written as C-key, so C-n means Control-N π
Meta keys are written as M-key, so M-x means Meta-X π¦ The Meta key is often labeled βAltβ or βOptionβ π«Ά
On keyboards without a Meta key, M-x means ESC x, which is press and release Escape, then press and release x, in that order πΈ That makes ESC the meta prefix β¨ The combination M-C-x means ESC Control-x: press and release Escape, then press and hold Control while pressing x, then release both π₯
On some keyboards the Meta key produces characters with the eighth bit (0200) set π You can use the enable-meta-key variable to control whether it does that, if the keyboard allows it π On lots of other setups, the terminal or terminal emulator turns the metafied key into a key sequence that starts with ESC, like we just talked about π§
If your Meta key produces a key sequence with the ESC meta prefix, you can make M-key key bindings you specify (see Readline Key Bindings below) do the same thing by setting the force-meta-prefix variable π
Readline commands can take numeric arguments, which usually act as a repeat count π’ Sometimes though, it's the sign of the argument that matters π Passing a negative argument to a command that works in the forward direction (for example, kill-line) makes that command work backward instead βͺ Commands whose behaviour with arguments is different from this are noted below π
The point is the current cursor position, and mark refers to a saved cursor position π The text between the point and the mark is called the region π·
When a command is described as killing text, the deleted text gets saved for possible future retrieval, which is called yanking πͺ The killed text goes into a kill ring π Consecutive kills pile their deleted text into one unit, so it can be yanked all at once π«Ά Commands that don't kill text separate the chunks of text on the kill ring π
ποΈ INITIALIZATION FILE ποΈ
Readline is customized by putting commands in an initialization file, aka the inputrc file π
The name of this file comes from the value of the INPUTRC environment variable β¨ If that variable is unset, the default is ~/.inputrc π If that file does not exist or can't be read, readline looks for /etc/inputrc π When a program that uses the readline library starts up, readline reads the initialization file and sets the key bindings and variables found there, before reading any user input π
There are only a few basic constructs allowed in the inputrc file πΈ Blank lines are ignored π«§ Lines starting with a # are comments π¬ Lines starting with a $ indicate conditional constructs π Every other line denotes key bindings and variable settings π
The default key bindings in this document can be changed using key binding commands in the inputrc file π Programs that use this library can also add their own commands and bindings π§
For example, placing
M-Control-u: universal-argument
or
C-Meta-u: universal-argument
into the inputrc would make M-C-u execute the readline command universal-argument π₯
Key bindings may contain the following symbolic character names: DEL, ESC, ESCAPE, LFD, NEWLINE, RET, RETURN, RUBOUT (a destructive backspace), SPACE, SPC, and TAB β¨οΈ
Okay and here's a bonus: in addition to command names, readline lets you bind a key to a string that gets inserted when the key is pressed. That's called a macro πͺ The difference between a macro and a command is that a macro is enclosed in single or double quotes π
π· Key Bindings π·
The syntax for controlling key bindings in the inputrc file is simple, no cap π«Ά All you need is the name of the command or the text of a macro, plus a key sequence to bind it to π The key sequence can be specified in one of two ways: as a symbolic key name, possibly with Meta- or Control- prefixes, or as a key sequence made of one or more characters enclosed in double quotes π The key sequence and the name are separated by a colon, and there can be no whitespace between the name and the colon π
When you use the form keyname:function-name or macro, keyname is the name of a key spelled out in English π¬π§ For example:
Control-u: universal-argument
Meta-Rubout: backward-kill-word
Control-o: "> output"
In the example above, C-u is bound to the function universal-argument, M-DEL is bound to the function backward-kill-word, and C-o runs the macro on the right hand side (aka it inserts the text β> outputβ into the line) π₯
In the second form, "keyseq":function-name or macro, keyseq is different from keyname above, because strings that spell out an entire key sequence can be written by putting the sequence inside double quotes β¨ Some GNU Emacs style key escapes can be used, as in the example below, but none of the symbolic character names are recognized here, so no RETURN in this form π
ββοΈ
"\C-u": universal-argument
"\C-x\C-r": re-read-init-file
"\e[11~": "Function Key 1"
In this example, C-u is again bound to the function universal-argument πΈ C-x C-r is bound to the function re-read-init-file, and ESC [ 1 1 ~ is bound to insert the text βFunction Key 1β π
The full set of GNU Emacs style escape sequences you can use when specifying key sequences is:
\C-β A control prefix.\M-β Adds the meta prefix, or converts the following character to a meta character, as described below underforce-meta-prefix.\eβ An escape character.\\β Backslash.\"β Literal", a double quote.\'β Literal', a single quote.
On top of the GNU Emacs style escapes, there's a second set of backslash escapes too π
\aβ alert (bell) π\bβ backspace\dβ delete\fβ form feed\nβ newline\rβ carriage return\tβ horizontal tab\vβ vertical tab\nnnβ The eight-bit character whose value is the octal valuennn(one to three digits) π’\xHHβ The eight-bit character whose value is the hexadecimal valueHH(one or two hex digits) π¦
When you're typing the text of a macro, you have to use single or double quotes to mark it as a macro definition β οΈ Unquoted text is assumed to be a function name. The backslash escapes listed above get expanded in the macro body. A backslash quotes any other character in the macro text, including"and', so be careful with those π
Bash lets you display or change the current readline key bindings with the bind builtin command π» The -o emacs or -o vi options to the set builtin change the editing mode during interactive use π Other programs that use this library provide similar mechanisms π§ And if a program doesn't offer any other way to add new bindings, a user can always edit the inputrc file and have readline re-read it π
π Variables π
Readline has variables you can use to customize its behaviour even further π
A variable can be set in the inputrc file with a statement of the form
set variable-name value
Except where noted, readline variables can take the values On or Off (without regard to case) β¨ Unrecognized variable names are ignored π«§ When readline reads a variable value, empty or null values, βonβ (case-insensitive), and β1β are all treated as On π Every other value is treated as Off π
The variables and their default values are:
active-region-start-colorπ (default: the terminfo standout string) β okay so this is a string variable that controls the text color and background for anything in the active region (checkenable-active-regionbelow for the deets). It can't take up any physical character positions on the display, so it should only be terminal escape sequences π . Readline sends it to the terminal right before it shows the active region text. It gets reset to the default whenever the terminal type changes. The default is the string that puts your terminal in standout mode, pulled from the terminal's terminfo description β¨. A sample value might be β\e[01;33mβ πactive-region-end-colorπ¦ (default: the terminfo string that restores standout) β this one is the undo button π. It cancels outactive-region-start-colorand gets your terminal back to "normal" look after the active region text is shown. Same rules apply: no physical character positions, only escape sequences, and it gets reset whenever the terminal type changes. Readline outputs it after displaying the active region text. The default is the string that restores the terminal from standout mode, again from terminfo πΈ. A sample value might be β\e[0mβ πbell-styleπ (default:audible) β this controls what happens when readline wants to ring the terminal bell. Set it tononeand readline never rings the bell π€«. Set it tovisibleand readline uses a visible bell if one is available β¨. Set it toaudibleand readline tries to ring the terminal's actual bell π₯.bind-tty-special-charsπ (default:On) β when this isOn, readline tries to bind the control characters the kernel's terminal driver treats specially over to their readline equivalents π§. These override the default readline bindings described here. Wanna see your current terminal settings, including those special control characters (usually cchars)? Typestty -aat a bash prompt π.blink-matching-parenπ§ (default:Off) β if this isOn, readline briefly moves the cursor to an opening parenthesis whenever you insert a closing one π.colored-completion-prefixπ (default:Off) β set it toOnand, when readline lists completions, the common prefix of the possible completions shows up in a different color β¨. The color definitions come from theLS_COLORSenvironment variable. If$LS_COLORShas a color defined for the custom suffix βreadline-colored-completion-prefixβ, readline uses that color for the common prefix instead of its default π«Ά.colored-statsπ¨ (default:Off) β withOn, readline shows possible completions in different colors so you can tell their file types apart π. Those color definitions also come from theLS_COLORSenvironment variable πΈ.comment-beginπ¬ (default: β#β) β this is the string the readlineinsert-commentcommand inserts π. That command is bound toM-#in emacs mode and to#in vi command mode π¦.completion-display-widthπ (default:-1) β this is how many screen columns get used to show possible matches when you're doing completion π . The value gets ignored if it's less than 0 or greater than the terminal screen width π. Setting it to0makes matches display one per line π. The default is-1β.completion-ignore-caseπ€ (default:Off) βOnmeans readline does filename matching and completion in a case-insensitive way π.completion-map-caseπ (default:Off) β if this isOnandcompletion-ignore-caseis enabled, readline treats hyphens (-) and underscores (_) as the same thing during case-insensitive filename matching and completion π«Ά.completion-prefix-display-lengthβοΈ (default:0) β this is the max length in characters of the common prefix of your possible completions that gets shown as-is π. When it's set above zero, readline swaps out any common prefix longer than this for an ellipsis when showing possible completions β¨. If a completion starts with a period and readline is completing filenames, it uses three underscores instead of an ellipsis π§.completion-query-itemsπ (default:100) β this decides when readline asks if you want to see the possible completions generated by thepossible-completionscommand π. It can be set to any integer that's zero or higher π . If the number of possible completions is greater than or equal to this value, readline asks whether or not you want to view them. Otherwise it just lists them on the terminal π. A zero value means readline should never ask, and negative values get treated as zero π« .convert-metaπ (default:On) β withOn, readline converts characters it reads that have the eighth bit set into an ASCII key sequence. It does this by clearing the eighth bit and adding an escape character in front, which turns the character into a meta-prefixed one π¦. The default isOn, but readline flips it toOffif the locale has characters whose encodings might include bytes with the eighth bit set π. This variable depends on theLC_CTYPElocale category, so it can change if the locale changes π. It also affects key bindings, so check the description offorce-meta-prefixbelow too π.disable-completionπ« (default:Off) βOnmeans readline stops word completion dead in its tracks π. Completion characters just get inserted into the line as if they'd been mapped toself-insertπ .echo-control-charactersπ (default:On) β when this isOnand your operating system says it supports it, readline echoes a character for any signal generated from the keyboard β‘.editing-modeβ¨οΈ (default:emacs) β this controls whether readline uses a set of key bindings similar to Emacs or to vi π. It can be set to eitheremacsorviπΈ.emacs-mode-stringπͺ (default:@) β ifshow-mode-in-promptis enabled, this string gets shown right before the last line of the primary prompt when emacs editing mode is active π. The value is expanded like a key binding, so the usual meta- and control- prefixes and backslash escape sequences all work β¨. The\1and\2escapes start and end sequences of non-printing characters, which is handy for sneaking a terminal control sequence into the mode string π§.enable-active-regionπ (default:On) β when this isOn, readline lets certain commands mark the region as active π¦. While the region is active, readline highlights the text in it using theactive-region-start-colorvalue, which defaults to the string that turns on the terminal's standout mode π₯. The active region shows text inserted bybracketed-pasteand any matching text found by incremental and non-incremental history searches π«Ά.enable-bracketed-pasteπ (default:On) β withOn, readline sets up the terminal so each paste goes into the editing buffer as one single string of characters, instead of being treated like each character was typed on the keyboard π. This is called bracketed-paste mode, and it stops readline from running any editing commands bound to key sequences that show up in the pasted text π‘οΈ.enable-keypadβ¨οΈ (default:Off) β withOn, readline tries to turn on the application keypad when it gets called π¦. Some systems need this to get the arrow keys working π.enable-meta-keyπ (default:On) β withOn, readline tries to enable any meta modifier key the terminal claims to support π . On lots of terminals, the Meta key is used to send eight-bit characters. This variable checks for the terminal capability that says the terminal can turn on and off a mode that sets the eighth bit of a character (0200) when the Meta key is held down while typing it (a meta character) π.expand-tildeπ (default:Off) β if this isOn, readline does tilde expansion when it tries word completion π«Ά.force-meta-prefixπ§² (default:Off) β withOn, readline changes how it handles key sequences containing\M-orMeta-(see Key Bindings above) π«. It converts a key sequence like\M-CorMeta-Cinto the two-character sequenceESC C, which adds the meta prefix πΈ. Ifforce-meta-prefixisOff(the default), readline checks theconvert-metavariable to decide whether to do this conversion π€. Ifconvert-metaisOn, readline does the conversion described above. If it'sOff, readline turns C into a meta character by setting the eighth bit (0200) instead π.history-preserve-pointπ (default:Off) β withOn, the history code tries to put the point in the same spot on each history line you pull up withprevious-historyornext-historyβ¨.history-sizeπ (default: unset) β this sets the max number of history entries saved in the history list π. If it's set to zero, any existing history entries get deleted and no new ones are saved π. If it's set to a value less than zero, the number of history entries isn't limited π. By default the number isn't limited either π«Ά. Settinghistory-sizeto a non-numeric value sets the max number of history entries to500π.horizontal-scroll-modeβοΈ (default:Off) β setting this toOnmakes readline use a single line for display. Instead of wrapping to a new line when input gets longer than the screen width, it scrolls the input horizontally on that one line π¦. This gets switched on automatically for terminals that are 1 line high π.input-metaπ’ (default:Off) β withOn, readline turns on eight-bit input, meaning it doesn't clear the eighth bit of the characters it reads, no matter what the terminal says it can support πͺ. The default isOff, but readline switches it toOnif the locale has characters whose encodings might include bytes with the eighth bit set π. This variable depends on theLC_CTYPElocale category, and its value can change if the locale changes π. The namemeta-flagis a synonym forinput-metaπ.isearch-terminatorsπ (default: βC-[C-jβ)
Okay so this is the rest of search-terminators π It's the string of characters that should end an incremental search without also running that character as a command. If you never give it a value, ESC and C-j end an incremental search for you πΈ
keymap(emacs) β Sets the current readline keymap ποΈ The valid names areemacs,emacs-standard,emacs-meta,emacs-ctlx,vi,vi-command, andvi-insert.viis the same asvi-command, andemacsis the same asemacs-standard. The default isemacs, but the value ofediting-modealso affects which keymap you get by default πkeyseq-timeout(500) β This is how long readline waits for another character when it's reading an ambiguous key sequence π«Ά Ambiguous means the input so far could already be a complete sequence, or it could keep going into a longer one. If readline gets no input before the timeout, it goes with the shorter complete sequence. The value is in milliseconds, so1000means readline waits one second for more input β³ If you set it to a value less than or equal to zero, or to something non-numeric, readline just waits until another key is pressed to decide which sequence to complete πmark-directories(On) β When this isOn, completed directory names get a slash appended πβ¨mark-modified-lines(Off) β When this isOn, readline shows history lines that have been modified with a preceding asterisk (*) πmark-symlinked-directories(Off) β When this isOn, completed names that are symbolic links to directories get a slash appended π¦ This depends on the value ofmark-directories, so it's not fully independent, bestie πmatch-hidden-files(On) β When this isOn, readline matches files whose names begin with a β.β (hidden files) during filename completion π΅οΈββοΈ If you set it toOff, you have to type the leading β.β yourself in the filename you want completed πΈmenu-complete-display-prefix(Off) β When this isOn, menu completion shows the common prefix of the list of possible completions (which might even be empty) before it starts cycling through the list πoutput-meta(Off) β When this isOn, readline displays characters with the eighth bit set directly, instead of as a meta-prefixed escape sequence π§ The default isOff, but readline switches it toOnif the locale has characters whose encodings might include bytes with the eighth bit set. This one depends on theLC_CTYPElocale category, so its value can change if the locale changes πpage-completions(On) β When this isOn, readline uses an internal pager that's kind of like more(1) to show one screenful of possible completions at a time πprefer-visible-bellβ Seebell-style. πprint-completions-horizontally(Off) β When this isOn, completions are sorted alphabetically across the row instead of going down the screen β‘οΈrevert-all-at-newline(Off) β When this isOn, readline undoes all changes to history lines before it returns when executingaccept-line. By default, history lines can be modified and keep their own individual undo lists across calls toreadline()πsearch-ignore-case(Off) β When this isOn, readline does both incremental and non-incremental history list searches case-insensitively πshow-all-if-ambiguous(Off) β This changes how the completion functions behave by default πββοΈ When it'sOn, words with more than one possible completion list the matches right away instead of just ringing the bell ποΈshow-all-if-unmodified(Off) β This works likeshow-all-if-ambiguous, but with a twist π« When it'sOn, words with more than one possible completion and no partial completion at all (the possible completions don't share a common prefix) list the matches right away instead of ringing the bell πshow-mode-in-prompt(Off) β When this isOn, a string gets added to the beginning of the prompt to show the editing mode:emacs,vi command, orvi insertionπ The mode strings are user-settable, likeemacs-mode-stringπ¨skip-completed-text(Off) β When this isOn, the default completion behavior changes when a single match gets inserted into the line π§© It only kicks in when you're completing in the middle of a word. If it's enabled, readline doesn't insert characters from the completion that match the characters after point in the word being completed, so the bit of the word after the cursor doesn't get duplicated π ββοΈvi-cmd-mode-string(((cmd))) β Ifshow-mode-in-promptis enabled, this string shows up right before the last line of the primary prompt when vi editing mode is active and you're in command mode π€ The value gets expanded like a key binding, so the usual meta- and control- prefixes and backslash escape sequences all work here. The\1and\2escapes start and end sequences of non-printing characters, which is how you can sneak a terminal control sequence into the mode string πͺvi-ins-mode-string(((ins))) β Same vibe asvi-cmd-mode-string, but this one shows up when vi editing mode is active and you're in insertion mode π It's expanded like a key binding too, with the same meta- and control- prefixes and backslash escapes available, and\1and\2work the same way for non-printing characters πΈvisible-stats(Off) β When this isOn, a character showing a file's type (as reported by stat(2)) gets appended to the filename when possible completions are listed ποΈ
β¨ Conditional Constructs β¨
Okay this part is giving C preprocessor vibes π§ Readline has a facility that works like the conditional compilation features of the C preprocessor, so you can make key bindings and variable settings depend on the result of some tests π There are four parser directives available, bestie π
$ifβ The$ifconstruct lets you make bindings based on the editing mode, the terminal you're using, or the application using readline π The text of the test, after any comparison operator, runs all the way to the end of the line. Unless it says otherwise, you don't need any characters to isolate it πmodeβ Themode=form of the$ifdirective checks whether readline is in emacs or vi mode π§ You can use it together with theset keymapcommand, for example to set bindings in theemacs-standardandemacs-ctlxkeymaps only when readline starts out in emacs mode π―termβ Theterm=form lets you include terminal-specific key bindings, maybe to bind the key sequences the terminal sends for its function keys β¨οΈ The word on the right side of the=gets tested against both the full name of the terminal and the part of the terminal name before the first-. That meansxtermmatches bothxtermandxterm-256color, for instance π¦versionβ The version test lets you compare against specific readline versions π’versionexpands to the current readline version. The comparison operators are=, (and==),!=,<=,>=,<, and>. The version number on the right side of the operator is a major version number, an optional decimal point, and an optional minor version (e.g.,7.1). If you leave out the minor version, it defaults to0π«Ά You can separate the operator from the stringversionand from the version number with whitespace π«applicationβ Theapplicationconstruct includes application-specific settings π§ββοΈ Each program using the readline library sets its application name, and an initialization file can test for a particular value. This could be used to bind key sequences to functions that are useful for one specific program. For instance, this command adds a key sequence that quotes the current or previous word in bash π
$if Bash
# Quote the current or previous word
"\C-xq": "\eb\"\ef\""
$endif
variableβ Thevariableconstruct gives you simple equality tests for readline variables and values π The permitted comparison operators are=,==, and!=. You have to separate the variable name from the comparison operator with whitespace, and the operator can be separated from the value on the right hand side with whitespace too. String and boolean variables can both be tested, but boolean variables have to be tested against the valuesonandoffπΈ
$elseβ Commands in this branch of the$ifdirective run if the test fails π$endifβ This command, like the one in the previous example, ends an$ifcommand π$includeβ This directive takes a single filename as an argument and reads commands and key bindings from that file π For example, this directive would read/etc/inputrc:
$include /etc/inputrc
π SEARCHING π
okay so readline has commands for digging through your command history for lines containing a string you pick π there are two search modes: incremental and non-incremental, and they're both lowkey iconic π§
Incremental searches start before you've finished typing. Every time you type a character of the search string, readline shows the next history entry that matches what you've typed so far π¦ you only need as many characters as it takes to find the entry you want, which is so efficient it's giving main character π In emacs editing mode, hit C-r to search backward through history, and C-s to search forward β¨ The characters in the value of the isearch-terminators variable are what end an incremental search. If that variable hasn't been given a value, ESC and C-j end it instead π«Ά Want to bail? C-g aborts the search and puts back your original line π Once the search ends, the history entry that contains your search string becomes the current line πΈ
To find more matches, just hit C-r or C-s again, depending on which way you want to go π₯ That searches backward or forward for the next entry matching what you've typed so far. Any other key sequence bound to a readline command also ends the search and runs that command instead π For example, a newline ends the search and accepts the line, so the command from history just runs π A movement command also ends the search, makes the last line found the current line, and starts editing it π
Readline remembers your last incremental search string π§ So if you type two C-rs in a row with no new characters for a new search string in between, readline reuses that remembered string π
Non-incremental searches wait until you've typed the entire search string before they start looking β That string can be something you type in, or it can already be part of the current line π
β¨ EDITING COMMANDS β¨
okay here's the list of command names and the default key sequences they're bound to π Commands without a key sequence next to them are unbound by default, so they're just sitting there waiting for you π
quick vocab check before we go π
point is where your cursor is right now. mark is a cursor position saved by the set-mark command π The text between point and mark is called the region π¦ readline also has a concept of an active region: when the region is active, readline's redisplay highlights it using the value of the active-region-start-color variable β¨ The enable-active-region variable turns that highlighting on and off π A few commands set the region to active, and those are noted below π«Ά
Commands for Moving
beginning-of-line(C-a) β jumps you to the start of the current line πΈ On some keyboards this might also be bound to the Home key πend-of-line(C-e) β jumps you to the end of the line π On some keyboards this might also be bound to the End key πforward-char(C-f) β moves you forward one character β‘οΈ On some keyboards this might also be bound to the right arrow key πbackward-char(C-b) β moves you back one character β¬ οΈforward-word(M-f) β moves forward to the end of the next word π¦ Words are made of alphanumeric characters, so letters and digits, nothing else π’backward-word(M-b) β moves back to the start of the current or previous word β¨ Same deal here: words are alphanumeric characters (letters and digits) π€previous-screen-lineβ tries to move point to the same physical screen column on the previous physical screen line π Heads up, this won't do anything useful if the current readline line doesn't take up more than one physical line, or if point isn't greater than the length of the prompt plus the screen width πnext-screen-lineβ tries to move point to the same physical screen column on the next physical screen line π Same warning: it won't work if the current readline line doesn't wrap onto more than one physical line, or if the current line's length isn't greater than the length of the prompt plus the screen width π«clear-display(M-C-l) β clears the screen and, if possible, the terminal's scrollback buffer, then redraws the current line so it sits at the very top of the screen π§Ήβ¨clear-screen(C-l) β clears the screen, then redraws the current line, leaving it at the top of the screen πΈ If you give it a numeric argument, it refreshes the current line without clearing the screen πredraw-current-lineβ refreshes the current line π
Commands for Manipulating the History
accept-line(Newline,Return) β accepts the line no matter where your cursor is π If the line isn't empty, it may get added to the history list for later recall withadd_history()π If the line is a modified history line, it gets restored to its original state πprevious-history(C-p) β fetches the previous command from the history list, moving back through it π°οΈ On some keyboards this might also be bound to the up arrow key β¬οΈnext-history(C-n) β fetches the next command from the history list, moving forward through it β© On some keyboards this might also be bound to the down arrow key β¬οΈbeginning-of-history(M-<) β jumps to the first line in the history π₯end-of-history(M->) β jumps to the end of the input history, which is the line you're currently typing πoperate-and-get-next(C-o) β accepts the current line to hand back to the calling application, as if you'd pressed newline π Then it fetches the line after the current one from history so you can edit it π¦ If you give it a numeric argument, that number picks which history entry to use instead of the current line π’fetch-historyβ with a numeric argument, grabs that entry from the history list and makes it the current line π§ With no argument, it moves back to the first entry in the history list π₯reverse-search-history(C-r) β searches backward starting at the current line and moves "up" through history as needed π This is an incremental search π¦ This command also sets the region to the matched text and activates the region β¨forward-search-history(C-s) β searches forward starting at the current line and moves "down" through history as needed π This is an incremental search πΈ This command also sets the region to the matched text and activates the region πnon-incremental-reverse-search-history(M-p) β searches backward from the current line using a non-incremental search for a string you supply π΅οΈ The string can match anywhere in a history line πnon-incremental-forward-search-history(M-n) β searches forward through history using a non-incremental search for a string you supply π΅οΈββοΈ The string can match anywhere in a history line π«Άhistory-search-backwardβ searches backward through history for the characters between the start of the current line and point π The match has to start at the beginning of a history line π― This is a non-incremental search π§ On some keyboards this might be bound to the Page Up key πhistory-search-forwardβ searches forward through history for the characters between the start of the current line and point βοΈ The match has to start at the beginning of a history line π― This is a non-incremental search π§ On some keyboards this might be bound to the Page Down key πhistory-substring-search-backwardβ searches backward through history for the characters between the start of the current line and point π This time the string can match anywhere in a history line π This is a non-incremental search π§history-substring-search-forwardβ searches forward through history for the characters between the start of the current line and point βοΈ The string can match anywhere in a history line π This is a non-incremental search π§yank-nth-arg(M-C-y) β inserts the first argument to the previous command (usually the second word on the previous line) at point π With an argument n, it inserts the nth word from the previous command, and the words there start counting at word 0 π’ A negative argument inserts the nth word counting from the end of the previous command π Once n is worked out, it uses the history expansion facilities to pull out that word, as if you'd typed the!nhistory expansion π§yank-last-arg(M-.,M-_) β inserts the last argument to the previous command, which is the last word of the previous history entry π«Ά With a numeric argument, it acts exactly likeyank-nth-argπ’ Successive calls move back through the history list, inserting the last word (or whichever word the first call's argument picked) from each line in turn π Any numeric argument given to those repeat calls decides which direction you move through history π§ A negative argument flips the direction (back or forward) π This uses the history expansion facilities to grab the last word, as if you'd typed the!$history expansion π
π Commands for Changing Text π
end-of-file(usuallyC-d) β okay so this is the character your terminal uses to mean "end of file," the onestty(1)sets up for you. If you press it when the line is empty and point is at the very beginning, readline treats it as the end of input and returnsEOF. Iconic behavior, honestly. π«Άdelete-char(C-d) β deletes the character at point. If this is bound to the same key as the tty EOF character (whichC-dusually is), check theend-of-fileentry above for what happens. On some keyboards it can also be bound to the Delete key. ποΈbackward-delete-char(Rubout) β deletes the character behind the cursor. Give it a numeric argument and the deleted text gets saved on the kill ring instead of just vanishing. πforward-backward-delete-charβ deletes the character under the cursor, unless the cursor is at the end of the line. Then it deletes the character behind the cursor instead. Very flexible, no cap. β¨quoted-insert(C-q,C-v) β adds the next character you type to the line verbatim. This is how you insert characters likeC-qitself, for example. πtab-insert(M-TAB) β inserts a tab character. Simple, but make it a moment. πΈself-insert(a,b,A,1,!,...) β inserts whatever character you typed. The everyday main character of this whole page. πbracketed-paste-beginβ this one is meant for the "bracketed paste" escape sequence some terminals send, and it's bound by default, so you don't have to do anything. It lets readline insert your pasted text as one single unit instead of treating every character like a separate keypress. The pasted characters go in as if each one was bound toself-insert, so no editing commands get run mid-paste. Protective energy. π‘οΈπ¦ Bracketed paste sets the region to the inserted text and activates the region. β¨transpose-chars(C-t) β drags the character before point forward over the character at point, and point moves forward too. If point is at the end of the line, it transposes the two characters before point instead. Negative arguments have no effect here, so don't bother. πtranspose-words(M-t) β drags the word before point past the word after point, and point moves past that word as well. If point is at the end of the line, it transposes the last two words on the line. Words swapping places, it's giving drama. πupcase-word(M-u) β uppercases the current (or following) word. With a negative argument, it uppercases the previous word instead, and point stays exactly where it is. π₯downcase-word(M-l) β lowercases the current (or following) word. With a negative argument, it lowercases the previous word, but point doesn't move. Quiet but powerful. πcapitalize-word(M-c) β capitalizes the current (or following) word. With a negative argument, it capitalizes the previous word, and point stays put. Respectfully, very cute. πoverwrite-modeβ toggles overwrite mode. With an explicit positive numeric argument, it switches to overwrite mode. With an explicit non-positive numeric argument, it switches to insert mode. This only affects emacs mode, because vi mode does overwrite its own way. π Every call toreadline()starts in insert mode, so you always begin fresh. π In overwrite mode, characters bound toself-insertreplace the text at point instead of pushing everything to the right. Characters bound tobackward-delete-charreplace the character before point with a space. By default this command is unbound, but on some keyboards it can be bound to the Insert key. π¦
π Killing and Yanking π
kill-line(C-k) β kills the text from point to the end of the current line. With a negative numeric argument, it kills backward from the cursor to the beginning of the line instead. πbackward-kill-line(C-x Rubout) β kills backward to the beginning of the current line. With a negative numeric argument, it kills forward from the cursor to the end of the line. Opposite-day vibes. πunix-line-discard(C-u) β kills backward from point to the beginning of the line, saving the killed text on the kill-ring. π§Ήkill-whole-lineβ kills all characters on the current line, no matter where point is. Full clear, no mercy. π₯kill-word(M-d) β kills from point to the end of the current word. If you're sitting between words, it kills up to the end of the next word. Word boundaries here are the same onesforward-worduses. πbackward-kill-word(M-Rubout) β kills the word behind point. Word boundaries are the same as the onesbackward-worduses. π«§unix-word-rubout(C-w) β kills the word behind point, using white space as the word boundary, and saves the killed text on the kill-ring. Classic. πunix-filename-ruboutβ kills the word behind point, using white space and the slash character as word boundaries, and saves the killed text on the kill-ring. Perfect for paths, bestie. πdelete-horizontal-space(M-\) β deletes all spaces and tabs around point. Tidy girl behavior. β¨kill-regionβ kills the text in the current region. πͺcopy-region-as-killβ copies the text in the region to the kill buffer, so you can yank it right away without losing the original. πΈcopy-backward-wordβ copies the word before point to the kill buffer. Word boundaries are the same asbackward-word. πcopy-forward-wordβ copies the word following point to the kill buffer. Word boundaries are the same asforward-word. πyank(C-y) β yanks the top of the kill ring into the buffer at point. Bringing the good stuff back. π§yank-pop(M-y) β rotates the kill ring and yanks the new top. This only works if the previous command wasyankoryank-pop, so keep that in mind. π
π’ Numeric Arguments π’
digit-argument(M-0,M-1,...,M--) β adds this digit to the argument already accumulating, or starts a new argument if there isn't one.M--starts a negative argument. π’universal-argumentβ another way to set an argument, no cap. If you follow this command with one or more digits (optionally with a leading minus sign), those digits become the argument. If you follow it with digits and then rununiversal-argumentagain, that ends the numeric argument, but the second call is otherwise ignored. π«Ά As a special case, ifuniversal-argumentis immediately followed by a character that is neither a digit nor a minus sign, the argument count for the next command gets multiplied by four. The count starts at one, so the first run makes it four, a second run makes it sixteen, and so on, each time multiplying by four. Exponential slay. π
π¨οΈ Completing π¨οΈ
complete(TAB) β attempts completion on the text before point. The actual completion is application-specific, so it depends on who's running it. π€·ββοΈ Bash, for instance, tries programmable completion first. If that doesn't work, it treats the text as a variable (if it begins with$), a username (if it begins with~), a hostname (if it begins with@), or a command (including aliases, functions, and builtins), checking each in turn. If none of those produce a match, it falls back to filename completion. π Gdb, on the other hand, lets you complete program functions and variables, and only attempts filename completion under certain circumstances. π The default readline completion is filename completion. πpossible-completions(M-?) β lists the possible completions of the text before point. When it displays them, readline sets the number of columns used for display to the first of these that applies, in this order: the value ofcompletion-display-width, the value of the environment variableCOLUMNS, or the screen width. πinsert-completions(M-*) β inserts all completions of the text before point thatpossible-completionswould have generated, separated by a space. π§menu-completeβ similar tocomplete, except it replaces the word being completed with a single match from the list of possible completions. Run it again and it steps through the list, inserting each match in turn. When it gets to the end of the list,menu-completerings the bell (depending on thebell-stylesetting) and restores the original text. An argument of n moves n positions forward through the matches, and a negative argument moves backward. This is meant to be bound toTAB, but it's unbound by default. πmenu-complete-backwardβ identical tomenu-complete, except it moves backward through the list, as ifmenu-completehad been given a negative argument. Also unbound by default. βͺexport-completionsβ performs completion on the word before point the way described above, then writes the list of possible completions to readline's output stream. It uses this format, with each piece on its own line:- the number of matches N;
- the word being completed;
S:E, where S and E are the start and end offsets of the word in the readline line buffer; then- each match, one per line
If there are no matches, the first line is 0, and this command doesn't print anything after the S:E. If there's only a single match, it prints a single line containing that match. If there's more than one match, it prints the common prefix of the matches on the first line after the S:E (this prefix may be empty), then the matches on the lines after that. In this case, N includes the line with the common prefix. π€
The user or application needs to be ready for a blank line, because it can totally happen. The intent is that the user or application reads N lines after the line containing S:E to get the match list. This command is unbound by default. π
delete-char-or-listβ deletes the character under the cursor if you're not at the beginning or end of the line (just likedelete-char). At the end of the line, it acts exactly likepossible-completions. Unbound by default. π§
π¬ Keyboard Macros π¬
start-kbd-macro(C-x () β begins saving the characters you type into the current keyboard macro. Recording mode, activate. π΄end-kbd-macro(C-x )) β stops saving the characters into the current keyboard macro and stores the definition. Cut! π¬call-last-kbd-macro(C-x e) β re-executes the last keyboard macro you defined, making its characters appear as if you typed them at the keyboard all over again. Replay. πβ¨print-last-kbd-macro() β prints the last keyboard macro you defined, in a format that works for the inputrc file. Copy-paste it and you're set. π¨οΈπ
β¨ Miscellaneous β¨
re-read-init-file (C-x C-r) π
okay so this one just re-reads your inputrc file π and brings in any bindings or variable assignments it finds in there. no restart needed, bestie π
abort (C-g) π
ββοΈ
this is your "nope, cancel that" button π it aborts the current editing command and rings the terminal's bell, but only if that matches your bell-style setting. so it's giving polite little ding or total silence depending on how you set it up π
do-lowercase-version (M-A, M-B, M-x, ...) π
if the metafied character x is uppercase, this runs whatever command is bound to the lowercase version of that same metafied character β¨ the behavior is undefined if x is already lowercase, so ngl just don't go there π
prefix-meta (ESC) π¦
this one metafies the next character you type. so ESC f is the same thing as Meta-f. iconic shortcut energy π
undo (C-_, C-x C-u) βͺ
incremental undo πΈ and it's remembered separately for each line, so your undos stay in their own little lane π«Ά
revert-line (M-r) π«£
this undoes all changes made to the line, like the nuclear option π₯ it's basically the same as running the undo command enough times to get the line back to how it started. full reset, no cap π§Ή
tilde-expand (M-~) π
performs tilde expansion on the current word π simple, clean, slay.
set-mark (C-@, M-<space>) π
sets the mark to the point where your cursor currently is π but if you give it a numeric argument, it puts the mark at that position instead. marking your spot, periodt β¨
exchange-point-and-mark (C-x C-x) π
swaps the point with the mark π so your cursor jumps to the saved position, and then the mark gets set to where your cursor used to be. it's a little switcheroo and honestly so satisfying π
character-search (C-]) π
reads a character and moves point to the next occurrence of that character π§ a negative argument makes it search for previous occurrences instead, so you can go backwards too π
character-search-backward (M-C-]) β¬
οΈ
reads a character and moves point to the previous occurrence of that character π a negative argument flips it and searches for subsequent occurrences. backwards is forwards if you're brave enough π
skip-csi-sequence π«§
okay this one is lowkey important π₯Ί it reads enough characters to eat up a multi-key sequence, like the ones for keys such as Home and End. CSI sequences start with a Control Sequence Indicator (CSI), which is usually ESC [. if this sequence is bound to "\e[", then keys that produce CSI sequences do nothing unless you've explicitly bound them to a readline command. so no stray characters sneaking into your editing buffer π
ββοΈβ¨ this one is unbound by default, but it's usually bound to ESC [.
insert-comment (M-#) π¬
without a numeric argument, this inserts the value of the readline comment-begin variable at the beginning of the current line π with a numeric argument it becomes a toggle π: if the characters at the start of the line don't match the value of comment-begin, it inserts the value. otherwise, it deletes the characters in comment-begin from the start of the line. either way, the line gets accepted like you hit newline. the default value of comment-begin makes the current line a shell comment π, and if a numeric argument removes that comment character, the line will get executed by the shell. β οΈ heads up, that's a spicy move, so double-check before you do it π
dump-functions π¨οΈ
prints all of the functions and their key bindings to the readline output stream π if you give it a numeric argument, the output gets formatted so you can paste it straight into an inputrc file π
dump-variables ποΈ
prints all of the settable variables and their values to the readline output stream π· same deal with a numeric argument: the output is formatted so it can become part of an inputrc file β¨
dump-macros π§Ύ
prints all of the readline key sequences bound to macros, plus the strings they output, to the readline output stream π¬ and with a numeric argument, it's formatted to be part of an inputrc file, obsessed π
execute-named-command (M-x) π―
reads a bindable readline command name from your input and runs the function it's bound to, as if the key sequence it's bound to showed up in the input πͺ if you give this one a numeric argument, it passes that argument along to the function it executes.
emacs-editing-mode (C-e) π
when you're in vi command mode, this switches readline over to emacs editing mode π
vi-editing-mode (M-C-j) π
when you're in emacs editing mode, this switches you over to vi editing mode π¦ pick your vibe, bestie π«Ά
π DEFAULT KEY BINDINGS π
okay so here's the default keymap list, bestie π
Anything with the eighth bit set gets written as M-<character>, and those are called metafied characters π¦ Every printable ASCII character that isn't on the emacs standard list is bound to self-insert, which just drops that character into your input line β¨ In vi insertion mode, anything not specifically listed is also self-insert π«Ά Characters that stty(1) or the terminal driver already handle for signals, like C-Z or C-C, keep that job π Upper and lower case metafied characters do the same thing in the emacs mode meta keymap πΈ And whatever's left over is unbound, which makes readline ring the bell π (that depends on the bell-style variable, so it's not always a bell π)
πΈ Emacs Mode πΈ
β¨ Emacs Standard bindings β¨
"C-@" set-mark
"C-A" beginning-of-line
"C-B" backward-char
"C-D" delete-char
"C-E" end-of-line
"C-F" forward-char
"C-G" abort
"C-H" backward-delete-char
"C-I" complete
"C-J" accept-line
"C-K" kill-line
"C-L" clear-screen
"C-M" accept-line
"C-N" next-history
"C-P" previous-history
"C-Q" quoted-insert
"C-R" reverse-search-history
"C-S" forward-search-history
"C-T" transpose-chars
"C-U" unix-line-discard
"C-V" quoted-insert
"C-W" unix-word-rubout
"C-Y" yank
"C-]" character-search
"C-_" undo
" " to "/" self-insert
"0" to "9" self-insert
":" to "~" self-insert
"C-?" backward-delete-char
π Emacs Meta bindings π
"M-C-G" abort
"M-C-H" backward-kill-word
"M-C-I" tab-insert
"M-C-J" vi-editing-mode
"M-C-L" clear-display
"M-C-M" vi-editing-mode
"M-C-R" revert-line
"M-C-Y" yank-nth-arg
"M-C-[" complete
"M-C-]" character-search-backward
"M-space" set-mark
"M-#" insert-comment
"M-&" tilde-expand
"M-*" insert-completions
"M--" digit-argument
"M-." yank-last-arg
"M-0" digit-argument
"M-1" digit-argument
"M-2" digit-argument
"M-3" digit-argument
"M-4" digit-argument
"M-5" digit-argument
"M-6" digit-argument
"M-7" digit-argument
"M-8" digit-argument
"M-9" digit-argument
"M-<" beginning-of-history
"M-=" possible-completions
"M->" end-of-history
"M-?" possible-completions
"M-B" backward-word
"M-C" capitalize-word
"M-D" kill-word
"M-F" forward-word
"M-L" downcase-word
"M-N" non-incremental-forward-search-history
"M-P" non-incremental-reverse-search-history
"M-R" revert-line
"M-T" transpose-words
"M-U" upcase-word
"M-X" execute-named-command
"M-Y" yank-pop
"M-\" delete-horizontal-space
"M-~" tilde-expand
"M-C-?" backward-kill-word
"M-_" yank-last-arg
π¦ Emacs Control-X bindings π¦
"C-XC-G" abort
"C-XC-R" re-read-init-file
"C-XC-U" undo
"C-XC-X" exchange-point-and-mark
"C-X(" start-kbd-macro
"C-X)" end-kbd-macro
"C-XE" call-last-kbd-macro
"C-XC-?" backward-kill-line
π§ VI Mode bindings π§
okay now the vi side, which is giving a whole different personality π Everything here is grouped by which mode you're in, insert or command π
π«§ VI Insert Mode functions π«§
"C-D" vi-eof-maybe
"C-H" backward-delete-char
"C-I" complete
"C-J" accept-line
"C-M" accept-line
"C-N" menu-complete
"C-P" menu-complete-backward
"C-R" reverse-search-history
"C-S" forward-search-history
"C-T" transpose-chars
"C-U" unix-line-discard
"C-V" quoted-insert
"C-W" vi-unix-word-rubout
"C-Y" yank
"C-[" vi-movement-mode
"C-_" vi-undo
" " to "~" self-insert
"C-?" backward-delete-char
π VI Command Mode functions π
"C-D" vi-eof-maybe
"C-E" emacs-editing-mode
"C-G" abort
"C-H" backward-char
"C-J" accept-line
"C-K" kill-line
"C-L" clear-screen
"C-M" accept-line
"C-N" next-history
"C-P" previous-history
"C-Q" quoted-insert
"C-R" reverse-search-history
"C-S" forward-search-history
"C-T" transpose-chars
"C-U" unix-line-discard
"C-V" quoted-insert
"C-W" vi-unix-word-rubout
"C-Y" yank
"C-_" vi-undo
" " forward-char
"#" insert-comment
"$" end-of-line
"%" vi-match
"&" vi-tilde-expand
"*" vi-complete
"+" next-history
"," vi-char-search
"-" previous-history
"." vi-redo
"/" vi-search
"0" beginning-of-line
"1" to "9" vi-arg-digit
";" vi-char-search
"=" vi-complete
"?" vi-search
"A" vi-append-eol
"B" vi-prev-word
"C" vi-change-to
"D" vi-delete-to
"E" vi-end-word
"F" vi-char-search
"G" vi-fetch-history
"I" vi-insert-beg
"N" vi-search-again
"P" vi-put
"R" vi-replace
"S" vi-subst
"T" vi-char-search
"U" revert-line
"W" vi-next-word
"X" vi-rubout
"Y" vi-yank-to
"\" vi-complete
"^" vi-first-print
"_" vi-yank-arg
"`" vi-goto-mark
"a" vi-append-mode
"b" vi-prev-word
"c" vi-change-to
"d" vi-delete-to
"e" vi-end-word
"f" vi-char-search
"h" backward-char
"i" vi-insertion-mode
"j" next-history
"k" previous-history
"l" forward-char
"m" vi-set-mark
"n" vi-search-again
"p" vi-put
"r" vi-change-char
"s" vi-subst
"t" vi-char-search
"u" vi-undo
"w" vi-next-word
"x" vi-delete
"y" vi-yank-to
"|" vi-column
"~" vi-change-case
π SEE ALSO π
- The Gnu Readline Library, Brian Fox and Chet Ramey
- The Gnu History Library, Brian Fox and Chet Ramey
- bash(1)
π FILES π
~/.inputrcβ the individual readline initialization file β¨
π¦ AUTHORS π¦
okay the credits, bestie π«Ά
- Brian Fox, Free Software Foundation
- bfox@gnu.org
- Chet Ramey, Case Western Reserve University
- chet.ramey@case.edu
π BUG REPORTS π
if you find a bug in readline, you should totally report it π But first, make sure it's really a bug, and that it shows up in the latest version of the readline library you have π
Once you've confirmed it's a real bug, mail a bug report to bug-readline@gnu.org π If you have a fix, you're welcome to send that too, periodt π₯ Suggestions and "philosophical" bug reports can go to bug-readline@gnu.org or get posted to the Usenet newsgroup gnu.bash.bug πΈ
Comments and bug reports about this manual page should go to chet.ramey@case.edu π
π BUGS π
it's too big and too slow π
and that's the whole page, bestie π Readline 8.3, last updated December 30, 2024, filed under READLINE(3) β¨π
π¦ where this page comes from
- ubuntu questing: readline-common 8.3-3 Β· GPL-3.0-or-later
- ubuntu resolute: readline-common 8.3-4 Β· GPL-3.0-or-later
- ubuntu stonking: readline-common 8.3-4 Β· GPL-3.0-or-later
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms