Any POSIX-compliant shell will implement a
vi command editing mode which can be enabled like
set -o vi and disabled like
set +o vi. A
vi editing mode will distinguish between insert and command modes. Each prompt should default to the input mode, but pressing the
ESC key will switch contexts to the command mode.
Some relevant features of this mode include:
- Redraw the current command line. Position the cursor at the same location on the redrawn line.
- Insert the character
'#' at the beginning of the current command line and treat the resulting edit line as a comment. This line shall be entered into the command history; see
- Display the possible shell word expansions (see Word Expansions) of the bigword at the current command line position.
- Insert the value of the alias named _letter. The symbol letter represents a single alphabetic character from the portable character set; implementations may support additional characters as an extension. If the
alias _letter contains other editing commands, these commands shall be performed as part of the insertion. If no
alias _letter is enabled, this command shall have no effect.
Note: the effects of
@_[letter] are recursive and special characters can be escaped for literal input effect with
- Set the current command line to be the countth previous command line in the shell command history. If count is not specified, it shall default to 1. The cursor shall be positioned on the first character of the new command. If a
- command would retreat past the maximum number of commands in effect for this shell (affected by the
$HISTSIZE environment variable), the terminal shall be alerted, and the command shall have no effect.
- Yank (that is, copy) the characters from the current cursor position to the position resulting from the motion command into the save buffer. A number count shall be applied to the motion command. If the motion command would move toward the beginning of the command line, the character under the current cursor position shall not be included in the set of yanked characters. If the motion command is
y, the entire current command line shall be yanked into the save buffer. The current cursor position shall be unchanged. If the count is larger than the number of characters between the current cursor position and the end of the command line toward which the motion command would move the cursor, this shall not be considered an error; all of the remaining characters in the aforementioned range shall be yanked.
- Yank the characters from the current cursor position to the end of the line into the save buffer. The current character position shall be unchanged.
- Put a copy of the current contents of the save buffer after the current cursor position. The current cursor position shall be advanced to the last character put from the save buffer. A count shall indicate how many copies of the save buffer shall be put.
- Put a copy of the current contents of the save buffer before the current cursor position. The current cursor position shall be moved to the last character put from the save buffer. A count shall indicate how many copies of the save buffer shall be put.
Many similar effects can be had via shell-specific line-editors (like
bind command via
~/.input.rc or the BSD-licensed