Emacs: Bookmark

By Xah Lee. Date: . Last updated: .

Emacs's Bookmarks is similar to browser's bookmark. It lets you easily open frequently needed files.

emacs bookmark 2017 04 11
Emacs Bookmark. M-x list-bookmark

Add a Bookmark

Open a file you want to bookmark. Then, Alt+x bookmark-setCtrl+x r m】. It'll add current file to bookmark file. It will prompt you for a name.

Bookmark can be a file or a directory.

List Bookmarks

Alt+x list-bookmarkCtrl+x r l】 → Open bookmark file.

When in bookmark file, press Enter ↵ to open the item under cursor.

Open a Bookmark

To open a bookmarked item, Alt+x bookmark-jumpCtrl+x r b】, then type a name.

You can type a asterisk * for wildcard. For example, “*today” will match “todo today”.

Remove / Rename Bookmark

When in the bookmark file:

Save Bookmark File

Alt+x bookmark-save to save the bookmark file. (Press 【s】 while in bookmark file)

Bookmarks are automatically saved when emacs quit. (since ~2014) 〔►see Emacs 24.4 New Features (released 2014-10) (2014-10)

You can control bookmark auto save behavior by bookmark-save-flag.

(setq bookmark-save-flag 1) ; everytime bookmark is changed, automatically save it

(setq bookmark-save-flag t) ; save bookmark when emacs quits

(setq bookmark-save-flag nil) ; never auto save.

How to Remember Bookmark Commands or Shortcuts?

Bookmark commands are under the menu 〖Edit ▸ Bookmarks〗.

emacs bookmark menu
emacs bookmark menu

When you are in bookmark file, Alt+x describe-modeCtrl+h m】 to see its commands and shortcuts.

Set Emacs to Open Bookmark File on Start

To have emacs open bookmark file on startup, add this to the end of your elisp init file:

(setq inhibit-splash-screen t)
(require 'bookmark)
(switch-to-buffer "*Bookmark List*")

Bookmark File Location

In emacs 24.x, bookmark file is at ~/.emacs.d/bookmarks.

In emacs 23.x, bookmark file is at ~/.emacs.bmk.

The default bookmark file path is stored in the variable bookmark-default-file. Alt+x describe-variableCtrl+h v】 to see its value.

Open File topics

  1. Emacs: File Manager, dired
  2. Emacs: Bookmark Tutorial
  3. Emacs: Open Recently Opened File
  4. Emacs: Open File Fast
  5. Emacs: Open Last Closed File
  6. Emacs: Open File Path Under Cursor

Buffer topics

  1. Emacs: List Buffers
  2. Emacs: Switch Buffer
  3. Emacs: New Empty Buffer
  4. Emacs: Next/Previous User Buffer
Like it? Buy Xah Emacs Tutorial. Thanks.