Emacs: Using Bookmark Feature

By Xah Lee. Date: . Last updated: .

This page is a tutorial on emacs's bookmark feature. Emacs's Bookmarks is similar to browser's bookmark. It lets you easily open frequently needed files.

emacs bookmark
Emacs's Bookmark feature.

Using Bookmark

Add a File to Bookmark

Open the file you want to add. Then, call bookmark-setCtrl+x r m】 . It will prompt you for a name.

Opening Bookmark File

To open bookmark, call bookmark-bmenu-listCtrl+x r l】. This displays your bookmarks.

bookmark-jump: Opening a Bookmarked Item

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

You can use * for wildcard. ➢ for example: *today will match todo today.

Saving Your Bookmark

Call bookmark-save to save it. (Press 【s】 while in bookmark)

Sometimes in or before 〔➤see Emacs 24.4 New Features (released 2014-10) (2014-10)〕, by default, bookmarks are automatically saved when emacs quit. Before, if you don't save it, newly added bookmarks will be for the current session only, and won't show up when you restart emacs.

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.

Removing Or Renaming Bookmark Item

When in the bookmark file:

How to Remember Bookmark Commands or Shortcuts?

Bookmark commands are right under the menu 〖Edit ▸ Bookmarks〗. If you forgot the commands or shortcuts, look at the menu. The menu is a great way to remember many emacs's commands.

emacs bookmark menu
emacs bookmark menu

Also, the bookmark commands all start with “bookmark-”. The only one you really need to remember is bookmark-bmenu-list. Once you have the bookmark open, call describe-modeCtrl+h m】 to see its commands and shortcuts.

Starting Emacs with Bookmark

To have emacs open bookmarks 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 Raw File Location

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

In emacs 23.x, it's at ~/.emacs.bmk.

The default location is controlled by the variable bookmark-default-file. Call describe-variableCtrl+h v】 to see its value.

You can set default bookmark location like this:

(setq bookmark-default-file  (concat user-emacs-directory "bookmarks"))

The syntax to load a bookmark file is this:

(bookmark-load bookmark-default-file t)

Open File topics

Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from my keyboard store.