This page is about Emacs’ Minibuffer History.
Different contexts use different minibuffer histories. For example, if you input a filename argument to a command such as
‘find-file’, it is added to a history of filename inputs.
You can later retrieve a previously entered input from a minibuffer history and reuse it (perhaps editing it first). Use the following key sequences to do that:
‘previous-history-element’) – retrieve the input before the one currently in the minibuffer
‘next-history-element’) – retrieve the input after the one currently in the minibuffer
‘previous-matching-history-element’) – Move to an earlier item in the minibuffer history that matches a regexp you enter.
‘next-matching-history-element’) – Move to a later item in the minibuffer history that matches a regexp you enter.
Naturally, these keys work only during minibuffer input.
‘M-n’ move one item through a history list each time you use them.
‘M-r’ are, by default, bound to
‘previous-complete-history-element’, respectively (see above). Alternatively, you might want to rebind
‘down’ to the history completion commands:
(define-key minibuffer-local-map (kbd "M-p") 'previous-complete-history-element) (define-key minibuffer-local-map (kbd "M-n") 'next-complete-history-element) (define-key minibuffer-local-map (kbd "<up>") 'previous-complete-history-element) (define-key minibuffer-local-map (kbd "<down>") 'next-complete-history-element)
‘C-r’in minibuffer, narrow the list by typing some patterns(multiple patterns are space-delimited string), select with up/down/pgup/pgdown/C-p/C-n/C-v/M-v, choose with enter.
Commands such as
‘C-x b’) create a new buffer of the given name if no such buffer exists. Killing a buffer does not automatically remove it from the buffer-name minibuffer history,
‘buffer-name-history’. That means that when you try to use that name later, a new buffer with that name is created. This might not be what you want most of the time.
This code removes a buffer name from
‘buffer-name-history’ when the buffer is killed:
(add-hook 'kill-buffer-hook (lambda () (setq buffer-name-history (delete* (buffer-name) buffer-name-history :test 'string=))))
You can just use EmacsLisp’s
‘delete’ here and drop the `
:test string=’, instead of requiring the CommonLisp library code (
cl-seq.el) at runtime for
‘equal’, which does the same thing here (uses
‘string=’), and about as efficiently. – DrewAdams