Every argument that you enter with the minibuffer is saved in a minibuffer history list so you can easily use it again later. You can use the following arguments to quickly fetch an earlier argument into the minibuffer:
previous-history-element).
next-history-element).
previous-matching-history-element).
next-matching-history-element).
While in the minibuffer, typing M-p or <Up>
(previous-history-element) moves up through the minibuffer
history list, one item at a time. Each M-p fetches an earlier
item from the history list into the minibuffer, replacing its existing
contents. Similarly, typing M-n or <Down>
(next-history-element) moves back down the history list,
fetching later entries into the minibuffer. You can think of these
commands as “backwards” and “forwards” through the history list.
If you type M-n in the minibuffer when there are no later entries in the minibuffer history (⁖, if you haven't previously typed M-p), Emacs tries fetching from a list of default argument: values that you are likely to enter. You can think of this as moving through the “future list” instead of the “history list”.
The input that M-p or M-n fetches into the minibuffer entirely replaces the existing contents of the minibuffer, so you can simply type <RET> to use it as an argument. You can also edit the text before you reuse it; this does not change the history element that you “moved” to, but your new argument does go at the end of the history list in its own right.
There are also commands to search forward or backward through the
history; they search for history elements that match a regular
expression. M-r (previous-matching-history-element)
searches older elements in the history, while M-s
(next-matching-history-element) searches newer elements. These
commands are unusual: they use the minibuffer to read the regular
expression even though they are invoked from the minibuffer. As with
incremental searching, an upper-case letter in the regular expression
makes the search case-sensitive (see Search Case). You can also
search through the history using an incremental search (see Isearch Minibuffer).
All uses of the minibuffer record your input on a history list, but there are separate history lists for different kinds of arguments. For example, there is a list for file names, used by all the commands that read file names. (As a special feature, this history list records the absolute file name, even if the name you entered was not absolute.)
There are several other specific history lists, including one for
buffer names, one for arguments of commands like query-replace,
one used by M-x for command names, and one used by
compile for compilation commands. Finally, there is one
“miscellaneous” history list that most minibuffer arguments use.
The variable history-length specifies the maximum length of a
minibuffer history list; adding a new element deletes the oldest
element if the list gets too long. If the value of
history-length is t, there is no maximum length.
The variable history-delete-duplicates specifies whether to
delete duplicates in history. If it is non-nil, adding a new
element deletes from the list all other elements that are equal to it.
The default is nil.