Following answer related to “Open Recent” in Emacs indicates that

After you press C-x C-f, press up and down to navigate the history of opened files.

I have added following lines but they do not show cycle behavior like up, down arrow keys

It says: beginning of history or end of defaults no next item

(define-key minibuffer-local-map (kbd "C-n") 'next-history-element)
(define-key minibuffer-local-map (kbd "C-p") 'previous-history-element)

[Q] Instead of using up or down arrow keys, is it possible to use keybinding as C-n(down) and C-p(up) to iterate after typing C-x C-f?

  • 1
    I just fired up an emacs -Q. C-h k <down arrow> after C-x X-f shows 'next-line-or-history-element. So you're almost there. bind 'next-line-or-history-element and 'previous-line-or-history-element.
    – RichieHH
    Feb 26 '20 at 13:49

Answer (just giving Fish):
Yes of course it is, this is Emacs.
Bound to up and down during find-file are the commands previous-line-or-history-element and next-line-or-history-element. So you should try to bind these functions to C-n and C-p.:

(define-key minibuffer-local-map (kbd "C-n") #'next-line-or-history-element)
(define-key minibuffer-local-map (kbd "C-p") #'previous-line-or-history-element)

Meta (teaching how to fish):
Question: How did I know which function is bound? Answer: I used the built in help functions. You can always press C-h k and then the key to get the documentation of that keystroke. So I found out what the bound functions are. Question: How can I see what key shortcuts are available, currently? Answer: press C-h m it shows you the current mode documentation and key shortcuts.

Get familiar with the emacs help system here you can see available help commands

Consider using following packages (install them via MELPA and the package manager)

  • ivy swiper counsel this enhances/replaces many default commands with more comfortable and autocompleting commands
  • helpful a much improved help system
  • 1
    ah. nicely explained.
    – RichieHH
    Feb 26 '20 at 13:50
  • It work! but it does not act as cycle, I guess its is normal behavior. Ah when I press C-h, it deletes a character :/
    – alper
    Feb 26 '20 at 15:40
  • @alper: See the Emacs manual, node DEL Does Not Delete for your question/problem about C-h deleting a char.
    – Drew
    Feb 26 '20 at 15:47

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.