Emacs: Open File Fast

By Xah Lee. Date: . Last updated: .

Here's a command that lets you open file fast.

It uses ido's interface to open file from emacs's bookmark list.

First, you need to add files you use frequently to emacs bookmark.

[see Emacs: Bookmark]

Put the following in your emacs init file.

(defun xah-open-file-fast ()
  "Prompt to open a file from bookmark `bookmark-bmenu-list'.
This command is similar to `bookmark-jump', but use `ido-mode' interface, and ignore cursor position in bookmark.

URL `http://ergoemacs.org/emacs/emacs_hotkey_open_file_fast.html'
Version 2017-04-26"
  (interactive)
  (require 'bookmark)
  (bookmark-maybe-load-default-file)
  (let (($this-bookmark
         (ido-completing-read "Open bookmark:" (mapcar (lambda ($x) (car $x)) bookmark-alist))))
    (find-file (bookmark-get-filename $this-bookmark))
    ;; (bookmark-jump -this-bookmark)
    ))

Give this command a easy key, such as F8.

[see Emacs: How to Define Keys]

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

For best efficiency, add a unique digit for each bookmark file name you use frequently, so that opening a file is just 3 keystrokes, for example, F8 7 Enter.

Why ignore bookmarked cursor position?

  1. emacs bookmark also records cursor position.
  2. when you open bookmark with bookmark-jump, it goes to the bookmarked cursor position.
  3. However, that may not be what you want. You want the last cursor position when you closed the file.
  4. For example, when the file is a blog. You constantly edit it. The bookmarked position will be off. So, each time you open it with bookmark, you'll have to move cursor back to a proper position. Annoying.

So, now xah-open-file-fast ignores the position in bookmark.

Note, you should have save-place-mode on. It saves last cursor position.

;; remember cursor position
(if (version< emacs-version "25.0")
    (progn
      (require 'saveplace)
      (setq-default save-place t))
  (save-place-mode 1))

File Topic

  1. File Manager, dired
  2. Emacs Bookmark
  3. Open Recently Opened
  4. Open File Fast
  5. Open Last Closed File
  6. Open File Path Under Cursor
  7. Open File in External App
  8. Renaming Files

Emacs Keybinding Tips

  1. Add Custom Keys to Enhance Productivity
  2. isearch by Arrow Keys
  3. Bind Number Pad Keys
  4. 1 Key for M-x
  5. Hotkey to Open File Fast
  6. Add Web Browser Back Key/Button to Info mode
  7. Ctrl+x and Dvorak

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs

Emacs Lisp

Misc