0

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?

Drew
  • 75,699
  • 9
  • 109
  • 225
alper
  • 1,238
  • 11
  • 30
  • 1
    I just fired up an emacs -Q. C-h k 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

1 Answers1

1

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.

Related:
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
jue
  • 4,476
  • 8
  • 20
  • 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](https://emacs.stackexchange.com/questions/55803/using-c-n-and-c-p-to-iterate-as-cycle-in-find-file-instead-of-up-down-arro) for your question/problem about `C-h` deleting a char. – Drew Feb 26 '20 at 15:47