ido-mode, but one thing I hate about it is that after
C-x C-f I cannot use
up/down keys to cycle through recently opened files, as it used to be for example with
iswitchb. How can I set
ido to work this way?
Looking at the customization options for
ido RET), I don't see any options for enabling the cycling behavior you describe.
You can, however, add the following to your init-file:
(require 'recentf) (defun ido-recentf-open () "Use `ido-completing-read' to find a recent file." (interactive) (if (find-file (ido-completing-read "Find recent file: " recentf-list)) (message "Opening file...") (message "Aborting"))) (global-set-key (kbd "C-x C-r") 'ido-recentf-open)
With this in place you can press C-x C-r to get Ido completion for selecting recently opened files.
By default, the 20 most recent files will be kept in the history. I suggest you crank that up to something like 150 by setting
(setq recentf-max-saved-items 150)
Bonus: Accessing recent files, on-steroids edition
I don't see it mentioned in a lot of places, but Ido Virtual Buffers make it super easy to access recent files. Enable them like so:
(setq ido-use-virtual-buffers t)
The behavior you get is this:
nil, refer to past ("virtual") buffers as well as existing ones.
Essentially it works as follows: Say you are visiting a file and the buffer gets cleaned up by
midnight.el. Later, you want to switch to that buffer, but find it's no longer open. With virtual buffers enabled, the buffer name stays in the buffer list (using the
ido-virtualface, and always at the end), and if you select it, it opens the file back up again. This allows you to think less about whether recently opened files are still open or not. Most of the time you can quit Emacs, restart, and then switch to a file buffer that was previously open as if it still were.
Though the bindings have evolved over time, as of today, when you invoke
ido-find-file-read-only, you can use the following bindings available in the default configuration:
- M-o invokes
- C-M-o invokes
Apart from these not being as ergonomically pleasant as the M-p and M-n bindings I had been used to before trying ido, they're also slow, and the consequent minibuffer chatter is distracting and confusing. ido does something more than just show a recently opened file name; it reports that it's "Searching for 'file name'...", perhaps out of reluctance to offer a name for a file that no longer exists.
The "Searching for" message comes from function
ido-make-merged-file-list. Reading the source, I don't see any way to disable whatever magic this function is doing.
You may consider rebinding the
ido-next-work-file pair to something more natural like C-M-p and C-M-n, or swapping the current M-p (
ido-prev-work-directory) and M-n (
ido-next-work-directory) bindings for these.
Here is the Emacs Lisp code to restore M-p and M-n to cycle through recent files, moving the default directory-focused bindings to C-M-p and C-M-n respectively:
(add-hook 'ido-setup-hook (lambda () (let ((kmap ido-file-dir-completion-map)) (let ((key '(meta ?n))) (define-key kmap (vector (cons 'control key)) (lookup-key kmap (vector key))) (define-key kmap (vector key) 'ido-next-work-file)) (let ((key '(meta ?p))) (define-key kmap (vector (cons 'control key)) (lookup-key kmap (vector key))) (define-key kmap (vector key) 'ido-prev-work-file)))))
The answer given by @itsjeyd is pretty complete. Let me just suggest a function:
(defun ido-choose-from-recentf () "Use ido to select a recently visited file from the `recentf-list'" (interactive) (find-file (ido-completing-read "Open file: " recentf-list nil t))) ;; bind it to "C-c f" (global-set-key (kbd "C-c f") 'ido-choose-from-recentf)
Courtesy of WikEmacs
helm-for-files works better than any of the above answers for the purpose of file name auto-completion and having nice search interface. Also, you can configure it to include any search items you like.