![[Home]](https://www.emacswiki.org/images/logo218x38.png)
This page is about Emacs bookmarks. Bookmarks record locations so you can return to them later.
Emacs bookmarking makes use of three things that are related but different: a bookmark list, a bookmark file, and a bookmark-list display. Understanding these is important to using Emacs bookmarks. They are explained at Bookmark Basics.
Some bookmarking commands to get you started:
‘C-x r m’ – set a bookmark at the current location (e.g. in a file)‘C-x r b’ – jump to a bookmark‘C-x r l’ – list your bookmarks‘M-x bookmark-delete’ – delete a bookmark by nameYour personal bookmark file is defined by option ‘bookmark-default-file’, which defaults to `~/.emacs.d/bookmarks` in the most recent Emacs versions and to `~/.emacs.bmk’ in older versions. The file is maintained automatically by Emacs as you create, change, and delete bookmarks.
(Bookmark+ makes it easy to have multiple bookmark files – different sets of bookmarks for different uses.)
Command ‘bookmark-bmenu-list’, bound to ‘C-x r l’, provides a convenient menu to access bookmarks.
The bookmark list (buffer ‘*Bookmark List*’) is like Dired or BufferMenu for bookmarks. (Emacs sometimes calls it the “bookmark menu list”, which is a misnomer.)
Some keys in ‘*Bookmark List*’:
‘a’ – show annotation for the current bookmark‘A’ – show all annotations for your bookmarks‘d’ – mark various entries for deletion (‘x’ – to delete them)‘e’ – edit the annotation for the current bookmark‘m’ – mark various entries for display and other operations, (‘v’ – to visit)‘o’ – visit the current bookmark in another window, keeping the bookmark list open ‘C-o’ – switch to the current bookmark in another window‘r’ – rename the current bookmarkYou can bookmark Info nodes also – just use ‘C-x r m’, as usual.
You can separate bookmarks into multiple different files by
bookmark-default-file to your string input.overwrite flag in bookmark-load to t.(defun book-open (file) (interactive (list (read-file-name "File: " "~/bookm/"))) (setq bookmark-default-file file) (bookmark-load file t t t) (bookmark-bmenu-list) (switch-to-buffer "*Bookmark List*")) (defun book-add (file) (interactive (list (read-file-name "File: " "~/bookm/"))) (setq bookmark-default-file file) (bookmark-load file t t t) (bookmark-set) (bookmark-save))
bookmark-alist will just grow bigger!If you hit ‘C-x C-f’ and then realize that you want a file that is bookmarked, you can get to the bookmark this way:
From: MatthiasMeulien Subject: Re: bookmarks and abbrevs Newsgroups: gnu.emacs.help Date: 17 Jun 2002 20:20:59 +0200
(defun bookmark-to-abbrevs () "Create abbrevs based on `bookmark-alist'." (dolist (bookmark bookmark-alist) (let* ((name (car bookmark)) (file (bookmark-get-filename name))) (define-abbrev global-abbrev-table name file))))
I did not realize how to use this until I googled and found the original post where the poster mentioned using C-x a e (expand-abbrev) and RET on the find-file prompt. Now, if we could make find-file grok this more or less automatically too… 😊 – MathiasDahl
You can do the same thing (access a file bookmark from ‘C-x C-f’ etc.) with Icicles – just hit ‘C-x m’. See Icicles - File-Name Input. – DrewAdams
Lisp:bookmark-add.el creates a buffer for working with bookmarks. Written by EugeneMarkov
‘M-x bookmark-open-in-simply-buffer’ – switch to *Bookmark list*.‘M-x bookmark-set-add’ – Add this bookmark to bookmarks list. To use history, hit Up and Down. The first Up inserts expression which is near to a point.‘M-x bookmark-jump-next-cyclic’, ‘M-x bookmark-jump-prev-cyclic’ – Cycle bookmarks.‘M-x bookmark-jump-backwards’ – Move to last cursor position right after uses of commands ‘bookmark-jump-next-cyclic’ and ‘bookmark-jump-prev-cyclic’.Using this method you’ll find frequently used bookmarks easily (cho-seiri-hou in Japanese). – rubikitch
(defadvice bookmark-jump (after bookmark-jump activate) (let ((latest (bookmark-get-bookmark bookmark))) (setq bookmark-alist (delq latest bookmark-alist)) (add-to-list 'bookmark-alist latest)))
Use OrgMode and OrgCapture to store bookmarks. Just visit a file/website/email and do M-x org-capture. With its hierarchy structure, you can sort bookmarks into categories.
(setq org-capture-templates '(("b" "Bookmarks!") ("bw" "Web" plain (file "~/org/book.org") "%A" :unnarrowed t) ("bl" "Local" plain (file "~/org/book.org") "%A" :unnarrowed t))) ;; Key Label Type Access Insert Options
zsh has a feature called ‘cd-able-vars’ which is similar to bookmarks but limited to directories on the local machine. Here’s some code to convert emacs’ bookmarks into code for zsh. First add this to your .zshrc:
setopt cd_able_vars
[[ -r ~/.zsh.bmk ]] && source ~/.zsh.bmkAdd this to your .emacs:
(defadvice bookmark-write-file (after local-directory-bookmarks-to-zsh-advice activate) (local-directory-bookmarks-to-zsh))
(defun local-directory-bookmarks-to-zsh () (interactive) (when (and (require 'tramp nil t) (require 'bookmark nil t)) (set-buffer (find-file-noselect "~/.zsh.bmk" t t)) (delete-region (point-min) (point-max)) (insert "# -*- mode:sh -*-\n") (let (collect-names) (mapc (lambda (item) (let ((name (replace-regexp-in-string "-" "_" (car item))) (file (cdr (assoc 'filename (if (cddr item) item (cadr item)))))) (when (and (not (tramp-tramp-file-p file)) (file-directory-p file)) (setq collect-names (cons (concat "~" name) collect-names)) (insert (format "%s=\"%s\"\n" name (expand-file-name file) name))))) bookmark-alist) (insert ": " (mapconcat 'identity collect-names " ") "\n")) (let ((backup-inhibited t)) (save-buffer)) (kill-buffer (current-buffer))))
With the previous approach, you can also write the variables for fish:
(defadvice bookmark-write-file (local-directory-bookmarks-to-fish))
(defun local-directory-bookmarks-to-fish () (interactive) (when (and (require 'tramp nil t) (require 'bookmark nil t)) (set-buffer (find-file-noselect "~/.fish.bmk" t t)) (delete-region (point-min) (point-max)) (insert "# -*- mode:fish -*-\n") (let (collect-names) (mapc (lambda (item) (let ((name (replace-regexp-in-string "-" "_" (car item))) (file (cdr (assoc 'filename (if (cddr item) item (cadr item)))))) (when (and (not (tramp-tramp-file-p file)) (file-directory-p file)) (setq collect-names (cons (concat "~" name) collect-names)) (insert (format "set -Ux %s \"%s\"\n" name (expand-file-name file) name))))) bookmark-alist) (insert ": " (mapconcat 'identity collect-names " ") "\n")) (let ((backup-inhibited t)) (save-buffer)) (kill-buffer (current-buffer))))
You will need to load the bookmarks file in ./config/fish/config.fish:
source ~/.fish.bmk
and override the cd function .config/fish/functions/cd.fish:
#!/bin/env fish
function cd -d "change directory, and activate virtualenvs, if available"
# first and foremost, change directory
builtin cd $argv 2> /dev/null
if test $status -gt 0
builtin cd $$argv
end
endYou can bookmark Info nodes. As an alternative, you can use Info+ to create a virtual Info book and use Info to navigate its nodes. If you also use Icicles you can have any number of persistent virtual Info books.
‘doremi-bookmarks’ lets you cycle among bookmarks using the up and down arrow keys or a mouse wheel.‘icicle-bookmark’ lets you cycle cycle among bookmarks. Narrow the candidates using completion.‘M-x anything-for-files’, ‘M-x anything-bookmark-ext’.‘eshell/cd’ with your bookmarks.bm.el)CategoryBookmarking CategoryHypermedia CategoryPersistence CategoryGlossary CategoryNavigation