Emacs: Hotkey to Open File Fast

By Xah Lee. Date: . Last updated: .

Here's a command that lets you open file fast, by typing a letter or digit. You can use this instead of Emacs Bookmark.

Put the following in your emacs init file.

(require 'ido) ; part of emacs

(defvar xah-filelist nil "Association list of file/dir paths. Used by `xah-open-file-fast'. Key is a short abbrev string, Value is file path string.")

(setq xah-filelist
      '(
        ("3emacs" . "~/.emacs.d/" )
        ("git" . "~/git/" )
        ("todo" . "~/todo.org" )
        ("keys" . "~/git/my_emacs_init/my_keybinding.el" )
        ("download" . "~/Downloads/" )
        ("pictures" . "~/Pictures/" )
        ;; more here
        ) )

(defun xah-open-file-fast ()
  "Prompt to open a file from `xah-filelist'.
URL `http://ergoemacs.org/emacs/emacs_hotkey_open_file_fast.html'
Version 2015-04-23"
  (interactive)
  (let ((-abbrevCode
         (ido-completing-read "Open:" (mapcar (lambda (-x) (car -x)) xah-filelist))))
    (find-file (cdr (assoc -abbrevCode xah-filelist)))))

Call xah-open-file-fast, then it will prompt with real-time name completion as you type.

You should assign it a key. For example, 【F8】, so you can open a file by 【F8 1】, 【F8 2】, etc. 〔►see Emacs: How to Define Keys

You need to modify the file list in xah-filelist for your own use.

You might add a unique digit for each file's abbrev, so that opening files becomes muscle memory of key press.

Open File topics

Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from Best Keyboard for Emacs