18.6.2 History Control

beginning-of-buffer-or-history (ESC-<) (gg) (unbound)

Move to the beginning of the buffer, or if already there, move to the first event in the history list.

beginning-of-line-hist

Move to the beginning of the line. If already at the beginning of the buffer, move to the previous history line.

beginning-of-history

Move to the first event in the history list.

down-line-or-history (^N ESC-[B) (j) (ESC-[B)

Move down a line in the buffer, or if already at the bottom line, move to the next event in the history list.

vi-down-line-or-history (unbound) (+) (unbound)

Move down a line in the buffer, or if already at the bottom line, move to the next event in the history list. Then move to the first non-blank character on the line.

down-line-or-search

Move down a line in the buffer, or if already at the bottom line, search forward in the history for a line beginning with the first word in the buffer.

If called from a function by the zle command with arguments, the first argument is taken as the string for which to search, rather than the first word in the buffer.

down-history (unbound) (^N) (unbound)

Move to the next event in the history list.

history-beginning-search-backward

Search backward in the history for a line beginning with the current line up to the cursor. This leaves the cursor in its original position.

end-of-buffer-or-history (ESC->) (unbound) (unbound)

Move to the end of the buffer, or if already there, move to the last event in the history list.

end-of-line-hist

Move to the end of the line. If already at the end of the buffer, move to the next history line.

end-of-history

Move to the last event in the history list.

vi-fetch-history (unbound) (G) (unbound)

Fetch the history line specified by the numeric argument. This defaults to the current history line (i.e. the one that isn’t history yet).

history-incremental-search-backward (^R ^Xr) (unbound) (unbound)

Search backward incrementally for a specified string. The search is case-insensitive if the search string does not have uppercase letters and no numeric argument was given. The string may begin with ‘^’ to anchor the search to the beginning of the line. When called from a user-defined function returns the following statuses: 0, if the search succeeded; 1, if the search failed; 2, if the search term was a bad pattern; 3, if the search was aborted by the send-break command.

A restricted set of editing functions is available in the mini-buffer. Keys are looked up in the special isearch keymap, and if not found there in the main keymap (note that by default the isearch keymap is empty). An interrupt signal, as defined by the stty setting, will stop the search and go back to the original line. An undefined key will have the same effect. Note that the following always perform the same task within incremental searches and cannot be replaced by user defined widgets, nor can the set of functions be extended. The supported functions are:

accept-and-hold
accept-and-infer-next-history
accept-line
accept-line-and-down-history

Perform the usual function after exiting incremental search. The command line displayed is executed.

backward-delete-char
vi-backward-delete-char

Back up one place in the search history. If the search has been repeated this does not immediately erase a character in the minibuffer.

accept-search

Exit incremental search, retaining the command line but performing no further action. Note that this function is not bound by default and has no effect outside incremental search.

backward-delete-word
backward-kill-word
vi-backward-kill-word

Back up one character in the minibuffer; if multiple searches have been performed since the character was inserted the search history is rewound to the point just before the character was entered. Hence this has the effect of repeating backward-delete-char.

clear-screen

Clear the screen, remaining in incremental search mode.

history-incremental-search-backward

Find the next occurrence of the contents of the mini-buffer. If the mini-buffer is empty, the most recent previously used search string is reinstated.

history-incremental-search-forward

Invert the sense of the search.

magic-space

Inserts a non-magical space.

quoted-insert
vi-quoted-insert

Quote the character to insert into the minibuffer.

redisplay

Redisplay the command line, remaining in incremental search mode.

vi-cmd-mode

Select the ‘vicmd’ keymap; the ‘main’ keymap (insert mode) will be selected initially.

In addition, the modifications that were made while in vi insert mode are merged to form a single undo event.

vi-repeat-search
vi-rev-repeat-search

Repeat the search. The direction of the search is indicated in the mini-buffer.

Any character that is not bound to one of the above functions, or self-insert or self-insert-unmeta, will cause the mode to be exited. The character is then looked up and executed in the keymap in effect at that point.

When called from a widget function by the zle command, the incremental search commands can take a string argument. This will be treated as a string of keys, as for arguments to the bindkey command, and used as initial input for the command. Any characters in the string which are unused by the incremental search will be silently ignored. For example,

zle history-incremental-search-backward forceps

will search backwards for forceps, leaving the minibuffer containing the string ‘forceps’.

history-incremental-search-forward (^S ^Xs) (unbound) (unbound)

Search forward incrementally for a specified string. The search is case-insensitive if the search string does not have uppercase letters and no numeric argument was given. The string may begin with ‘^’ to anchor the search to the beginning of the line. The functions available in the mini-buffer are the same as for history-incremental-search-backward.

history-incremental-pattern-search-backward
history-incremental-pattern-search-forward

These widgets behave similarly to the corresponding widgets with no -pattern, but the search string typed by the user is treated as a pattern, respecting the current settings of the various options affecting pattern matching. See Filename Generation for a description of patterns. If no numeric argument was given lowercase letters in the search string may match uppercase letters in the history. The string may begin with ‘^’ to anchor the search to the beginning of the line.

The prompt changes to indicate an invalid pattern; this may simply indicate the pattern is not yet complete.

Note that only non-overlapping matches are reported, so an expression with wildcards may return fewer matches on a line than are visible by inspection.

history-search-backward (ESC-P ESC-p) (unbound) (unbound)

Search backward in the history for a line beginning with the first word in the buffer.

If called from a function by the zle command with arguments, the first argument is taken as the string for which to search, rather than the first word in the buffer.

vi-history-search-backward (unbound) (/) (unbound)

Search backward in the history for a specified string. The string may begin with ‘^’ to anchor the search to the beginning of the line.

A restricted set of editing functions is available in the mini-buffer. An interrupt signal, as defined by the stty setting, will stop the search. The functions available in the mini-buffer are: accept-line, backward-delete-char, vi-backward-delete-char, backward-kill-word, vi-backward-kill-word, clear-screen, redisplay, quoted-insert and vi-quoted-insert.

vi-cmd-mode is treated the same as accept-line, and magic-space is treated as a space. Any other character that is not bound to self-insert or self-insert-unmeta will beep and be ignored. If the function is called from vi command mode, the bindings of the current insert mode will be used.

If called from a function by the zle command with arguments, the first argument is taken as the string for which to search, rather than the first word in the buffer.

history-search-forward (ESC-N ESC-n) (unbound) (unbound)

Search forward in the history for a line beginning with the first word in the buffer.

If called from a function by the zle command with arguments, the first argument is taken as the string for which to search, rather than the first word in the buffer.

vi-history-search-forward (unbound) (?) (unbound)

Search forward in the history for a specified string. The string may begin with ‘^’ to anchor the search to the beginning of the line. The functions available in the mini-buffer are the same as for vi-history-search-backward. Argument handling is also the same as for that command.

infer-next-history (^X^N) (unbound) (unbound)

Search in the history list for a line matching the current one and fetch the event following it.

insert-last-word (ESC-_ ESC-.) (unbound) (unbound)

Insert the last word from the previous history event at the cursor position. If a positive numeric argument is given, insert that word from the end of the previous history event. If the argument is zero or negative insert that word from the left (zero inserts the previous command word). Repeating this command replaces the word just inserted with the last word from the history event prior to the one just used; numeric arguments can be used in the same way to pick a word from that event.

When called from a shell function invoked from a user-defined widget, the command can take one to three arguments. The first argument specifies a history offset which applies to successive calls to this widget: if it is -1, the default behaviour is used, while if it is 1, successive calls will move forwards through the history. The value 0 can be used to indicate that the history line examined by the previous execution of the command will be reexamined. Note that negative numbers should be preceded by a ‘--’ argument to avoid confusing them with options.

If two arguments are given, the second specifies the word on the command line in normal array index notation (as a more natural alternative to the numeric argument). Hence 1 is the first word, and -1 (the default) is the last word.

If a third argument is given, its value is ignored, but it is used to signify that the history offset is relative to the current history line, rather than the one remembered after the previous invocations of insert-last-word.

For example, the default behaviour of the command corresponds to

zle insert-last-word -- -1 -1

while the command

zle insert-last-word -- -1 1 -

always copies the first word of the line in the history immediately before the line being edited. This has the side effect that later invocations of the widget will be relative to that line.

vi-repeat-search (unbound) (n) (unbound)

Repeat the last vi history search.

vi-rev-repeat-search (unbound) (N) (unbound)

Repeat the last vi history search, but in reverse.

up-line-or-history (^P ESC-[A) (k) (ESC-[A)

Move up a line in the buffer, or if already at the top line, move to the previous event in the history list.

vi-up-line-or-history (unbound) (-) (unbound)

Move up a line in the buffer, or if already at the top line, move to the previous event in the history list. Then move to the first non-blank character on the line.

up-line-or-search

Move up a line in the buffer, or if already at the top line, search backward in the history for a line beginning with the first word in the buffer.

If called from a function by the zle command with arguments, the first argument is taken as the string for which to search, rather than the first word in the buffer.

up-history (unbound) (^P) (unbound)

Move to the previous event in the history list.

history-beginning-search-forward

Search forward in the history for a line beginning with the current line up to the cursor. This leaves the cursor in its original position.

set-local-history

By default, history movement commands visit the imported lines as well as the local lines. This widget lets you toggle this on and off, or set it with the numeric argument. Zero for both local and imported lines and nonzero for only local lines.