0

In Vim I could retrieve past commands by typing :<first-letter-of-command>↑ . If my Vim command history is:-

colorscheme +
source %
shell
set spell
colorscheme?
bp
term

Typing :s↑ directly shows me the command set spell.

How can I achieve this in Emacs? I already have the line (savehist-mode 1) in my init.el but pressing M-x <first-letter-of-command>↑ does not work. I am using Emacs 25.3.1 on Windows 10.

Edit: My question is not a duplicate of this suggested question. My question is about accessing past commands based on the first letter of the command. For instance, pressing M - x b followed by the up arrow should take me to the most recent command beginning with the letter 'b'. The suggested question is about going through the command history one-by-one without using the arrow keys.

  • Possible duplicate of emacs.stackexchange.com/q/4189/11241 . – Steve Vinoski Dec 7 '19 at 15:15
  • @SteveVinoski how is it a duplicate? My question is about accessing past commands using the first Letter of the command – aks Dec 7 '19 at 15:17
  • Does this answer your question? Access minibuffer history without using arrow keys – Drew Dec 7 '19 at 15:29
  • 1
    @aks Correct; prefix your letter with ^ in your regexp, e.g. ^a, to force the match to be at the beginning of the matched history item. – Steve Vinoski Dec 7 '19 at 15:56
  • 1
    There are lots of history completion extensions (Helm, Ivy, etc.) which are much more effective (e.g. you can search for words in any order in the history). Don't stop at the built in completion, because there are better ways. – Tom Dec 8 '19 at 10:39
0

You can use minibuffer history search to find a matching item via M-r. For example, to find the previous history item beginning with the letter 'a':

M-x M-r ^a Enter

Note that this is a regexp search, so you need to prefix the search letter with the ^ regexp metacharacter to force matches to the beginning of matched history items.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.