Emacs Advent Calendar 04: The Minibuffer

Fri 2015-12-04

Emacs uses the minibuffer to ask for user input such as file or buffer names. The usual text editing commands can be used, but there is additional functionality.

History The minibuffer stores a history of previous input. To cycle through these entries use M-p or <UP> to go backwards and M-n or <DOWN> to go forwards. Searching throug items works with M-r and M-s respectively.

Newslines <RET> is used to submit the argument to the minibuffer, so how to enter a literal newline? Either insert a quoted newline with C-q C-j or just use C-o.

Filenames When the minibuffer is used to read the name of a file to visit, the default directory is the one of file visited in the current buffer. Path levels can be deleted by M-backspace.

A little known but useful feature is the following: Entering an absolute path starting with a slash after the suggested path makes emacs ignore everything before the double slash. For example, '/etc/hosts' can be entered as '~/code/foo//etc/hosts' if you happen to be in '~/code/foo/'. The same works for absolute paths starting with a tilde: '/ect/pacman.d/gnupg/~/code/foo/bar.tex' is equivalent to '~/code/foo/bar.tex'.

For more information see section 8 (The Minibuffer) of the Emacs Reference Manual.

Tags:

This text by Ludger Sandig is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.