EDITLINE(7) Standards, Environments, and Macros EDITLINE(7)

editline - line editing user interface

When a program using the editline(3) library prompts for an input string using the function el_wgets(3), it reads characters from the terminal. Invalid input bytes that do not form characters are silently discarded. For each character read, one editor command is executed. The mapping of input characters to editor commands depends on the editing mode. There are three editing modes: vi insert mode, vi command mode, and emacs mode. The default is vi insert mode. The program can switch the default to emacs mode by using the el_set(3) or el_parse(3) functions, and the user can switch to emacs mode either in the editrc(5) configuration file or interactively with the ed-command editor command, in all three cases executing the bind Fl e builtin command.

If trying to read from the terminal results in end of file or an error, the library signals end of file to the program and does not return a string.

All default bindings described below can be overridden by individual programs and can be changed with the editrc(5) bind builtin command.

In the following tables, `Ctrl-' indicates a character with the bit 0x40 flipped, and `Meta-' indicates a character with the bit 0x80 set. In vi insert mode and in emacs mode, all Meta-characters considered printable by the current locale(1) are bound to ed-insert instead of to the editor command listed below. Consequently, in UTF-8 mode, most of the Meta-characters are not directly accessible because their code points are occupied by printable Unicode characters, and Meta-characters are usually input using the em-meta-next editor command. For example, to enter `Meta-B' in order to call the ed-prev-word editor command in emacs mode, call em-meta-next by pressing and releasing the escape key (or equivalently, Ctrl-[), then press and release the `B' key. If you have configured a Meta-key on your keyboard, for example with `setxkbmap' -option altwin:left_meta_win , the Ctrl-Meta-characters are directly accessible. For example, to enter `Ctrl-Meta-H' in order to call the ed-delete-prev-word editor command in emacs mode, hold down the keys `Ctrl', `Meta', and `H' at the same time. Alternatively, press and release the escape key, then press and release `Ctrl-H'.

In vi input mode, input characters are bound to the following editor commands by default: It Ctrl-D, EOF Ta vi-list-or-eof It Ctrl-H, BS Ta vi-delete-prev-char It Ctrl-J, LF Ta ed-newline It Ctrl-M, CR Ta ed-newline It Ctrl-Q Ta ed-tty-start-output It Ctrl-S Ta ed-tty-stop-output It Ctrl-U Ta vi-kill-line-prev It Ctrl-V Ta ed-quoted-insert It Ctrl-W Ta ed-delete-prev-word It Ctrl-[, ESC Ta vi-command-mode It Ctrl-\, QUIT Ta ed-tty-sigquit It Ctrl-?, DEL Ta vi-delete-prev-char

All other input characters except the NUL character (Ctrl-@) are bound to ed-insert.

In vi command mode, input characters are bound to the following editor commands by default: It Ctrl-A Ta ed-move-to-beg It Ctrl-C, INT Ta ed-tty-sigint It Ctrl-E Ta ed-move-to-end It Ctrl-H, BS Ta ed-delete-prev-char It Ctrl-J, LF Ta ed-newline It Ctrl-K Ta ed-kill-line It Ctrl-L, FF Ta ed-clear-screen It Ctrl-M, CR Ta ed-newline It Ctrl-N Ta ed-next-history It Ctrl-O Ta ed-tty-flush-output It Ctrl-P Ta ed-prev-history It Ctrl-Q Ta ed-tty-start-output It Ctrl-R Ta ed-redisplay It Ctrl-S Ta ed-tty-stop-output It Ctrl-U Ta vi-kill-line-prev It Ctrl-W Ta ed-delete-prev-word It Ctrl-[, ESC Ta em-meta-next It Ctrl-\, QUIT Ta ed-tty-sigquit It Space Ta ed-next-char It # Ta vi-comment-out It $ Ta ed-move-to-end It % Ta vi-match It + Ta ed-next-history It , Ta vi-repeat-prev-char It - Ta ed-prev-history It . Ta vi-redo It / Ta vi-search-prev It 0 Ta vi-zero It 1 to 9 Ta ed-argument-digit It : Ta ed-command It ; Ta vi-repeat-next-char It ? Ta vi-search-next It @ Ta vi-alias It A Ta vi-add-at-eol It B Ta vi-prev-big-word It C Ta vi-change-to-eol It D Ta ed-kill-line It E Ta vi-end-big-word It F Ta vi-prev-char It G Ta vi-to-history-line It I Ta vi-insert-at-bol It J Ta ed-search-next-history It K Ta ed-search-prev-history It N Ta vi-repeat-search-prev It O Ta ed-sequence-lead-in It P Ta vi-paste-prev It R Ta vi-replace-mode It S Ta vi-substitute-line It T Ta vi-to-prev-char It U Ta vi-undo-line It W Ta vi-next-big-word It X Ta ed-delete-prev-char It Y Ta vi-yank-end It [ Ta ed-sequence-lead-in It ^ Ta ed-move-to-beg It _ Ta vi-history-word It a Ta vi-add It b Ta vi-prev-word It c Ta vi-change-meta It d Ta vi-delete-meta It e Ta vi-end-word It f Ta vi-next-char It h Ta ed-prev-char It i Ta vi-insert It j Ta ed-next-history It k Ta ed-prev-history It l Ta ed-next-char It n Ta vi-repeat-search-next It p Ta vi-paste-next It r Ta vi-replace-char It s Ta vi-substitute-char It t Ta vi-to-next-char It u Ta vi-undo It v Ta vi-histedit It w Ta vi-next-word It x Ta ed-delete-next-char It y Ta vi-yank It | Ta vi-to-column It ~ Ta vi-change-case It Ctrl-?, DEL Ta ed-delete-prev-char It Meta-O Ta ed-sequence-lead-in It Meta-[ Ta ed-sequence-lead-in

In emacs mode, input characters are bound to the following editor commands by default: It 0 to 9 Ta ed-digit It Ctrl-@, NUL Ta em-set-mark It Ctrl-A Ta ed-move-to-beg It Ctrl-B Ta ed-prev-char It Ctrl-C, INT Ta ed-tty-sigint It Ctrl-D, EOF Ta em-delete-or-list It Ctrl-E Ta ed-move-to-end It Ctrl-F Ta ed-next-char It Ctrl-H, BS Ta em-delete-prev-char It Ctrl-J, LF Ta ed-newline It Ctrl-K Ta ed-kill-line It Ctrl-L, FF Ta ed-clear-screen It Ctrl-M, CR Ta ed-newline It Ctrl-N Ta ed-next-history It Ctrl-O Ta ed-tty-flush-output It Ctrl-P Ta ed-prev-history It Ctrl-Q Ta ed-tty-start-output It Ctrl-R Ta ed-redisplay It Ctrl-S Ta ed-tty-stop-output It Ctrl-T Ta ed-transpose-chars It Ctrl-U Ta ed-kill-line It Ctrl-V Ta ed-quoted-insert It Ctrl-W Ta em-kill-region It Ctrl-X Ta ed-sequence-lead-in It Ctrl-Y Ta em-yank It Ctrl-Z, TSTP Ta ed-tty-sigtstp It Ctrl-[, ESC Ta em-meta-next It Ctrl-\, QUIT Ta ed-tty-sigquit It Ctrl-] Ta ed-tty-dsusp It Ctrl-?, DEL Ta em-delete-prev-char It Ctrl-Meta-H Ta ed-delete-prev-word It Ctrl-Meta-L Ta ed-clear-screen It Ctrl-Meta-_ Ta em-copy-prev-word It Meta-0 to 9 Ta ed-argument-digit It Meta-B Ta ed-prev-word It Meta-C Ta em-capitol-case It Meta-D Ta em-delete-next-word It Meta-F Ta em-next-word It Meta-L Ta em-lower-case It Meta-N Ta ed-search-next-history It Meta-O Ta ed-sequence-lead-in It Meta-P Ta ed-search-prev-history It Meta-U Ta em-upper-case It Meta-W Ta em-copy-region It Meta-X Ta ed-command It Meta-[ Ta ed-sequence-lead-in It Meta-b Ta ed-prev-word It Meta-c Ta em-capitol-case It Meta-d Ta em-delete-next-word It Meta-f Ta em-next-word It Meta-l Ta em-lower-case It Meta-n Ta ed-search-next-history It Meta-p Ta ed-search-prev-history It Meta-u Ta em-upper-case It Meta-w Ta em-copy-region It Meta-x Ta ed-command It Ctrl-Meta-? Ta ed-delete-prev-word

The remaining ascii(7) characters in the range 0x20 to 0x7e are bound to ed-insert.

If standard output is not connected to a terminal device or el_set(3) was used to set EL_EDITMODE to 0, all input character bindings are disabled and all characters typed are appended to the edit buffer. In that case, the edit buffer is returned to the program after a newline or carriage return character is typed, or after the first character typed if el_set(3) was used to set EL_UNBUFFERED to non-zero.

Most editor commands accept an optional argument. The argument is entered by prefixing the editor command with one or more of the editor commands ed-argument-digit, ed-digit, em-universal-argument, or vi-zero. When an argument is not provided, it defaults to 1. For most editor commands, the effect of an argument is to repeatedly execute the command that number of times.

When talking about a character string from a left character to a right character, the left character is included in the string, while the right character is not included.

If an editor command causes an error, the input character is discarded, no action occurs, and the terminal bell is rung. In case of a non-fatal error, the terminal bell is also rung, but the editor command takes effect anyway.

In the following list, the default key bindings are listed after each editor command.

If in argument input mode, append the input digit to the argument being read. Otherwise, switch to argument input mode and use the input digit as the most significant digit of the argument. It is an error if the input character is not a digit or if the existing argument is already greater than a million.
Clear the screen and display the edit buffer at the top. Ignore any argument.
Read a line from the terminal bypassing the normal line editing functionality and execute that line as an editrc(5) builtin command. If in vi command mode, also switch back to vi insert mode. Ignore any argument.
Delete the character at the cursor position. With an argument, delete that number of characters. In emacs mode, it is an error if the cursor is at the end of the edit buffer. In vi mode, the last character in the edit buffer is deleted in that case, and it is an error if the buffer is empty.
Delete the character to the left of the cursor position. With an argument, delete that number of characters. It is an error if the cursor is at the beginning of the edit buffer.
Move to the left to the closest beginning of a word, delete the string from that position to the cursor, and save it to the cut buffer. With an argument, delete that number of words. It is an error if the cursor is at the beginning of the edit buffer.
If in argument input mode, append the input digit to the argument being read. Otherwise, call ed-insert. It is an error if the input character is not a digit or if the existing argument is already greater than a million.
Discard the edit buffer and indicate end of file to the program. Ignore any argument.
Discard the input character and do nothing.
In insert mode, insert the input character left of the cursor position. In replace mode, overwrite the character at the cursor and move the cursor to the right by one character position. Accept an argument to do this repeatedly. It is an error if the input character is the NUL character (Ctrl-@). Failure to enlarge the edit buffer also results in an error.
Delete the string from the cursor position to the end of the line and save it to the cut buffer. Ignore any argument.
In vi mode, move the cursor to the first non-space character in the edit buffer. In emacs mode, move the cursor to the beginning of the edit buffer. Ignore any argument. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank.
Move the cursor to the end of the edit buffer. Ignore any argument. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank.
Append a newline character to the edit buffer and return the edit buffer to the program. Ignore any argument.
Move the cursor one character position to the right. With an argument, move by that number of characters. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. It is an error if the cursor is already at the end of the edit buffer.
Replace the edit buffer with the next history line. That line is older than the current line. With an argument, go forward by that number of history lines. It is a non-fatal error to advance by more lines than are available.
Move the cursor down one line. With an argument, move down by that number of lines. It is an error if the edit buffer does not contain enough newline characters to the right of the cursor position.
Move the cursor one character position to the left. With an argument, move by that number of characters. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. It is an error if the cursor is already at the beginning of the edit buffer.
Replace the edit buffer with the previous history line. That line is newer than the current line. With an argument, go back by that number of lines. It is a non-fatal error to back up by more lines than are available.
Move the cursor up one line. With an argument, move up by that number of lines. It is an error if the edit buffer does not contain enough newline characters to the left of the cursor position.
Move the cursor to the left to the closest beginning of a word. With an argument, repeat that number of times. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. It is an error if the cursor is already at the beginning of the edit buffer.
Read one character from the terminal bypassing the normal line editing functionality and call ed-insert on it. If trying to read the character returns end of file or an error, call ed-end-of-file instead.
Redisplay everything. Ignore any argument.
Replace the edit buffer with the next matching history entry.
Replace the edit buffer with the previous matching history entry.

both: Meta-O, Meta-[ Call a macro. See the section about Macros below for details.
Discard the contents of the edit buffer and start from scratch. Ignore any argument.
Exchange the character at the cursor position with the one to the left of it and move the cursor to the character to the right of the two exchanged characters. Ignore any argument. It is an error if the cursor is at the beginning of the edit buffer or if the edit buffer contains less than two characters.
This editor command always results in an error.
Capitalize the string from the cursor to the end of the current word. That is, if it contains at least one alphabetic character, convert the first alphabetic character to upper case, and convert all characters to the right of it to lower case. In any case, move the cursor to the next character after the end of the current word.
Copy the string from the beginning of the current word to the cursor and insert it to the left of the cursor. Move the cursor to the character after the inserted string. It is an error if the cursor is at the beginning of the edit buffer.
Copy the string from the cursor to the mark to the cut buffer. It is an error if the mark is not set.
Delete the string from the cursor to the end of the current word and save it to the cut buffer. It is an error if the cursor is at the end of the edit buffer.
If the cursor is not at the end of the line, delete the character at the cursor. If the edit buffer is empty, indicate end of file to the program. It is an error if the cursor is at the end of the edit buffer and the edit buffer is not empty.
Delete the character to the left of the cursor. It is an error if the cursor is at the beginning of the edit buffer.
Exchange the cursor and the mark.
Exchange the two characters to the left of the cursor. It is an error if the cursor is on the first or second character of the edit buffer.
Emacs incremental next search.
Emacs incremental reverse search.
Delete the entire contents of the edit buffer and save it to the cut buffer.
Delete the string from the cursor to the mark and save it to the cut buffer. It is an error if the mark is not set.
Convert the characters from the cursor to the end of the current word to lower case.
Set the bit 0x80 on the next character typed. Unless the resulting code point is printable, holding down the `Meta-' key while typing that character is a simpler way to achieve the same effect.
Move the cursor to the end of the current word. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. It is an error if the cursor is already at the end of the edit buffer.
Set the mark at the current cursor position.
Switch from insert to overwrite mode or vice versa.
If in argument input mode, multiply the argument by 4. Otherwise, switch to argument input mode and set the argument to 4. It is an error if the existing argument is already greater than a million.
Convert the characters from the cursor to the end of the current word to upper case.
Paste the cut buffer to the left of the cursor.
Switch to vi insert mode. Unless the cursor is already at the end of the edit buffer, move it one character position to the right.
Switch to vi insert mode and move the cursor to the end of the edit buffer.
If an alias function was defined by calling the el_set(3) or el_wset(3) function with the argument EL_ALIAS_TEXT , read one character from the terminal bypassing the normal line editing functionality, call the alias function passing the argument that was specified with EL_ALIAS_TEXT as the first argument and the character read, with an underscore prepended, as the second argument, and pass the string returned from the alias function to el_wpush(3). It is an error if no alias function is defined or if trying to read the character results in end of file or an error.
Change the case of the character at the cursor and move the cursor one character position to the right. It is an error if the cursor is already at the end of the edit buffer.
Delete the string from the cursor to the position specified by the following movement command and save a copy of it to the cut buffer. When given twice in a row, instead delete the whole contents of the edit buffer and save a copy of it to the cut buffer. In either case, switch to vi insert mode after that.
Delete the string from the cursor position to the end of the line and save it to the cut buffer, then switch to vi insert mode.
Discard pending actions and arguments and switch to vi command mode. Unless the cursor is already at the beginning of the edit buffer, move it to the left by one character position.
Insert a `#' character at the beginning of the edit buffer and return the edit buffer to the program.
Delete the string from the cursor to the position specified by the following movement command and save a copy of it to the cut buffer. When given twice in a row, instead delete the whole contents of the edit buffer and save a copy of it to the cut buffer.
Delete the character to the left of the cursor. It is an error if the cursor is already at the beginning of the edit buffer.
Move the cursor to the end of the current space delimited word. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. It is an error if the cursor is already at the end of the edit buffer.
Move the cursor to the end of the current word. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. It is an error if the cursor is already at the end of the edit buffer.
Insert the first word from the most recent history entry after the cursor, move the cursor after to the character after the inserted word, and switch to vi insert mode. It is an error if there is no history entry or the most recent history entry is empty.
Enter insert mode.
Move the cursor to the beginning of the edit buffer and switch to vi insert mode.
Delete the string from the beginning of the edit buffer to the cursor and save it to the cut buffer.
If the edit buffer is empty, indicate end of file to the program. It is an error if the edit buffer is not empty.
Consider opening and closing parentheses, braces, and brackets as delimiters. If the cursor is not at a delimiter, move it to the right until it gets to one, then move it to the matching delimiter. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. It is an error if there is no delimiter at the cursor or in the string to the right of the cursor, or if the first such delimiter has no matching delimiter.
Move the cursor to the right to the beginning of the next space delimited word. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. It is an error if the cursor is already at the end of the edit buffer or on its last character.
Read one character from the terminal bypassing the normal line editing functionality and move the cursor to the right to the next instance of that character in the edit buffer. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. If trying to read the character results in end of file or an error, call ed-end-of-file instead. It is an error if the character is not found searching to the right in the edit buffer.
Move the cursor to the right to the beginning of the next word. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. It is an error if the cursor is already at the end of the edit buffer or on its last character.
Insert a copy of the cut buffer to the right of the cursor. It is an error if the cut buffer is empty.
Insert a copy of the cut buffer to the left of the cursor. It is an error if the cut buffer is empty.
Move the cursor to the left to the next beginning of a space delimited word. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. It is an error if the cursor is already at the beginning of the edit buffer.
Read one character from the terminal bypassing the normal line editing functionality and move the cursor to the left to the next instance of that character in the edit buffer. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. If trying to read the character results in end of file or an error, call ed-end-of-file instead. It is an error if the character is not found searching to the left in the edit buffer.
Move the cursor to the left to the next beginning of a word. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. It is an error if the cursor is already at the beginning of the edit buffer.
Redo the last non-motion command.
Repeat the most recent character search in the same search direction. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank.
Repeat the most recent character search in the opposite search direction. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank.
Repeat the most recent history search in the same search direction.
Repeat the most recent history search in the opposite search direction.
Switch to vi replace mode, and automatically switch back to vi command mode after the next character typed. See ed-insert for a description of replace mode. It is an error if the cursor is at the end of the edit buffer.
Switch to vi replace mode. This is a variant of vi insert mode; see ed-insert for the difference.
Replace the edit buffer with the next matching history entry.
Replace the edit buffer with the previous matching history entry.
Delete the character at the cursor and switch to vi insert mode.
Delete the entire contents of the edit buffer, save a copy of it in the cut buffer, and enter vi insert mode.
Move the cursor to the column specified as the argument. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank.
Replace the edit buffer with the specified history entry.
Read one character from the terminal bypassing the normal line editing functionality and move the cursor to the right to the character before the next instance of that character in the edit buffer. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. If trying to read the character results in end of file or an error, call ed-end-of-file instead. It is an error if the character is not found searching to the right in the edit buffer.
Read one character from the terminal bypassing the normal line editing functionality and move the cursor to the left to the character after the next instance of that character in the edit buffer. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank. If trying to read the character results in end of file or an error, call ed-end-of-file instead. It is an error if the character is not found searching to the left in the edit buffer.
Undo the last change.
Undo all changes to the edit buffer.
Copy the string from the cursor to the position specified by the following movement command to the cut buffer. When given twice in a row, instead copy the whole contents of the edit buffer to the cut buffer.
Copy the string from the cursor to the end of the edit buffer to the cut buffer.
If in argument input mode, multiply the argument by ten. Otherwise, move the cursor to the beginning of the edit buffer. Can be used as a movement command after vi_change_meta, vi_delete_meta, or vi_yank.

If an input character is bound to the editor command ed-sequence-lead-in, editline attempts to call a macro. If the input character by itself forms the name of a macro, that macro is executed. Otherwise, additional input characters are read until the string read forms the name of a macro, in which case that macro is executed, or until the string read matches the beginning of none of the existing macro names, in which case the string including the final, mismatching character is discarded and the terminal bell is rung.

There are two kinds of macros. Command macros execute a single editor command. Keyboard macros return a string of characters that is appended as a new line to the Input Queue .

The following command macros are defined by default in vi command mode and in emacs mode: It Esc [ A, Esc O A Ta ed-prev-history It Esc [ B, Esc O B Ta ed-next-history It Esc [ C, Esc O C Ta ed-next-char It Esc [ D, Esc O D Ta ed-prev-char It Esc [ F, Esc O F Ta ed-move-to-end It Esc [ H, Esc O H Ta ed-move-to-beg

In vi command mode, they are also defined by default without the initial escape character.

In addition, the editline library tries to bind the strings generated by the arrow keys as reported by the terminfo(5) database to these editor commands, unless that would clobber user settings.

In emacs mode, the two-character string ``Ctrl-X Ctrl-X'' is bound to the em-exchange-mark editor command.

The editline library maintains an input queue operated in FIFO mode. Whenever it needs an input character, it takes the first character from the first line of the input queue. When the queue is empty, it reads from the terminal.

A line can be appended to the end of the input queue in several ways: It By calling one of the keyboard Macros . It By calling the editor command vi-redo. It By calling the editor command vi-alias. It By pressing a key in emacs incremental search mode that doesn't have a special meaning in that mode but returns to normal emacs mode. It If an application program directly calls the functions el_push(3) or el_wpush(3), it can provide additional, program-specific ways of appending to the input queue.

mg(1), vi(1), editline(3), el_wgets(3), el_wpush(3), el_wset(3), editrc(5)

This manual page first appeared in Ox 6.0 and Nx 8 .

-nosplit This manual page was written by

Ingo Schwarze <Mt schwarze@openbsd.org .>

May 7, 2016