Endless Parentheses

Concise ramblings on Emacs productivity.

Predicting the future with M-n

This is one of those small functionalities that makes your life considerably easier, and yet a surprising number of people don’t know about it. When Emacs prompts you for something in the minibuffer, you might be aware that you can navigate back and forth in the prompt’s history with M-p and M-n, but did you know you can even step into the future?

Well, sort of… At least that’s the spirit. If you type M-p at the prompt, Emacs fills the prompt with previous items from the history. On the other hand, if you type M-n, Emacs will try to guess from context what your next input is going to be. The meaning of this depends on the command (some of these require Emacs 24.5).

  • In file prompts, hitting M-n fills in the name of the current file. This is very useful with write-file or with dired commands like copy or move.
  • M-x tries to find a command name under point.
  • In query-replace-regexp it fills in the symbol at point, which is usually a pretty good guess of what you want to replace. And you can hit M-n a second time to get \_<symbol-delimiters\_> around the symbol.
  • As Marco points out in the comments, if you have two dired windows open, file or directory prompts in one window fill in the directory name of the other window.

These are the ones I use most often, but I’m sure there are more commands that support this feature, and it’s always worth trying it out with your favorite ones.

Tags: keybind, emacs

Say thanks on Gratipay
comments powered by Disqus