GNU Emacs
Emacs
Registers

Registers

Emacs registers are compartments where you can save text, rectangles, positions, and other things for later use. Once you save text or a rectangle in a register, you can copy it into the buffer once or many times; once you save a position in a register, you can jump back to that position once or many times. Each register has a name that consists of a single character, which we will denote by r; r can be a letter (such as a) or a number (such as 1); case matters, so register a is not the same as register A. You can also set a register in non-alphanumeric characters, for instance C-d by using for example C-q C-d. A register can store a position, a piece of text, a rectangle, a number, a window or frame configuration, a buffer name, or a file name, but only one thing at any given time. Whatever you store in a register remains there until you store something else in that register. To see what register r contains, use M-x view-register:

M-x view-register RET r
Display a description of what register r contains.

All of the commands that prompt for a register will by default display a preview window that lists the existing registers (if there are any) and their current values, after a short delay. This and other aspects of prompting for a register can be customized by setting the value of register-use-preview, which can have the following values:

traditional
With this value, which is the default, Emacs behaves like it did in all the versions before Emacs 29: it shows a preview of existing registers after a delay, and lets you overwrite the values of existing registers by typing a single character, the name of the register. The preview appears after the delay determined by the customizable variable register-preview-delay, which specifies the delay in seconds; setting it to nil disables the preview (but you can still explicitly request a preview window by pressing C-h or F1 when Emacs prompts for a register).
t
This value requests a more flexible preview of existing registers. The preview appears immediately when Emacs prompts for a register (thus register-preview-delay has no effect), and the preview window provides navigation: by using C-n and C-p (or the UP and DOWN arrow keys), you can move between the registers in the preview window. To overwrite the value of an existing registers in this mode, you need to type RET after selecting the register by navigation or typing its name. In addition, the registers shown by the preview are filtered according to the command that popped the preview: for example, the preview shown by insert-register will only show registers whose values can be inserted into the buffer, omitting registers which hold window configurations, positions, and other un-insertable values.
insist
This value is like t, but in addition you can press the same key as the name of register one more time to exit the minibuffer, instead of pressing RET.
nil
This value requests behavior similar to traditional, but the preview is shown without delay, and is filtered according to the command.
never
This value is like nil, but it disables the preview.

Bookmarks record files and positions in them, so you can return to those positions when you look at the file again. Bookmarks are similar in spirit to registers, so they are also documented in this chapter.

Saving Positions in Registers

C-x r SPC r
Record the position of point and the current buffer in register r (point-to-register).
C-x r j r
Jump to the position and buffer saved in register r (jump-to-register).

Typing C-x r SPC (point-to-register), followed by a character r, saves both the position of point and the current buffer in register r. The register retains this information until you store something else in it. The command C-x r j r switches to the buffer recorded in register r, pushes a mark, and moves point to the recorded position. (The mark is not pushed if point was already at the recorded position, or in successive calls to the command.) The contents of the register are not changed, so you can jump to the saved position any number of times. If you use C-x r j to go to a saved position, but the buffer it was saved from has been killed, C-x r j tries to create the buffer again by visiting the same file. Of course, this works only for buffers that were visiting files.

Saving Text in Registers

When you want to insert a copy of the same piece of text several times, it may be inconvenient to yank it from the kill ring, since each subsequent kill moves that entry further down the ring. An alternative is to store the text in a register and later retrieve it.

C-x r s r
Copy region into register r (copy-to-register).
C-x r i r
Insert text from register r (insert-register).
M-x append-to-register RET r
Append region to text in register r. When register r contains text, you can use C-x r + (increment-register) to append to that register. Note that command C-x r + behaves differently if r contains a number. Number Registers.
M-x prepend-to-register RET r
Prepend region to text in register r.

C-x r s r stores a copy of the text of the region into the register named r. If the mark is inactive, Emacs first reactivates the mark where it was last set. The mark is deactivated at the end of this command. Mark. C-u C-x r s r, the same command with a prefix argument, copies the text into register r and deletes the text from the buffer as well; you can think of this as moving the region text into the register. M-x append-to-register RET r appends the copy of the text in the region to the text already stored in the register named r. If invoked with a prefix argument, it deletes the region after appending it to the register. The command prepend-to-register is similar, except that it prepends the region text to the text in the register instead of appending it. When you are collecting text using append-to-register and prepend-to-register, you may want to separate individual collected pieces using a separator. In that case, configure a register-separator and store the separator text in to that register. For example, to get double newlines as text separator during the collection process, you can use the following setting.

(setq register-separator ?+)
(set-register register-separator "\n\n")

C-x r i r inserts in the buffer the text from register r. Normally it leaves point after the text and sets the mark before, without activating it. With a prefix argument, it instead puts point before the text and the mark after.

Saving Rectangles in Registers

A register can contain a rectangle instead of linear text. Rectangles, for basic information on how to specify a rectangle in the buffer.

C-x r r r
Copy the region-rectangle into register r (copy-rectangle-to-register). With prefix argument, delete it as well.
C-x r i r
Insert the rectangle stored in register r (if it contains a rectangle) (insert-register).

The C-x r i r (insert-register) command, previously documented in Text Registers, inserts a rectangle rather than a text string, if the register contains a rectangle.

Saving Window and Frame Configurations in Registers

You can save the window configuration of the selected frame in a register, or even the configuration of all windows in all frames, and restore the configuration later. Window Convenience, for information about window configurations.

C-x r w r
Save the state of the selected frame's windows in register r (window-configuration-to-register).
C-x r f r
Save the state of all frames, including all their windows (a.k.a. frameset), in register r (frameset-to-register).

Use C-x r j r to restore a window or frame configuration. This is the same command used to restore a cursor position. When you restore a frame configuration, any existing frames not included in the configuration become invisible. If you wish to delete these frames instead, use C-u C-x r j r.

Keeping Numbers in Registers

There are commands to store a number in a register, to insert the number in the buffer in decimal, and to increment it. These commands can be useful in keyboard macros (Keyboard Macros).

C-u number C-x r n r
Store number into register r (number-to-register).
C-u number C-x r + r
If r contains a number, increment the number in that register by number. Note that command C-x r + (increment-register) behaves differently if r contains text. Text Registers.
C-x r i r
Insert the number from register r into the buffer.

C-x r i is the same command used to insert any other sort of register contents into the buffer. C-x r + with no numeric argument increments the register value by 1; C-x r n with no numeric argument stores zero in the register.

Keeping File and Buffer Names in Registers

C-x r F r
Store the currently visited file or directory in register r (file-to-register).
C-x r B r
Store the currently visited buffer in register r (buffer-to-register).

If you visit certain files or buffers frequently, you can visit them more conveniently if you put their names in registers. Typing C-x r F (file-to-register), followed by a character r, saves a reference to the currently visited file in register r. You can then visit the file using jump-to-register by typing C-x r j r. With a prefix argument, file-to-register prompts for a file name to store in the register. Typing C-x r B (buffer-to-register), followed by a character r, saves a reference to the currently visited buffer in register r. You can then revisit the buffer using jump-to-register. With a prefix argument, buffer-to-register prompts for a buffer name to store in the register. If you store a buffer name which is visiting a file in a register, and the buffer is then closed, the register is automatically converted to a file reference, allowing you to quickly re-open the closed file.

Keyboard Macro Registers

If you need to execute a keyboard macro (Keyboard Macros) frequently, it is more convenient to put it in a register or save it (Save Keyboard Macro). C-x C-k x r (kmacro-to-register) stores the last keyboard macro in register r. To execute the keyboard macro in register r, type C-x r j /r/. (This is the same command used to jump to a position or restore a frameset.)

Bookmarks

Bookmarks are somewhat like registers in that they record positions you can jump to. Unlike registers, they have long names, and they persist automatically from one Emacs session to the next. The prototypical use of bookmarks is to record where you were reading in various files.

C-x r m RET
Set the bookmark for the visited file, at point.
C-x r m bookmark RET
Set the bookmark named bookmark at point (bookmark-set).
C-x r M bookmark RET
Like C-x r m, but don't overwrite an existing bookmark.
C-x r b bookmark RET
Jump to the bookmark named bookmark (bookmark-jump).
C-x r l
List all bookmarks (list-bookmarks).
M-x bookmark-save
Save all the current bookmark values in the default bookmark file.

To record the current position in the visited file, use the command C-x r m, which sets a bookmark using the visited file name as the default for the bookmark name. If you name each bookmark after the file it points to, then you can conveniently revisit any of those files with C-x r b (bookmark-jump), and move to the position of the bookmark at the same time. In addition to recording the current position, on graphical displays C-x r m places a special image on the left fringe (Fringes) of the screen line corresponding to the recorded position, to indicate that there's a bookmark there. This can be controlled by the user option bookmark-fringe-mark: customize it to nil to disable the fringe mark. The default value is bookmark-mark, which is the bitmap used for this purpose. When you later use C-x r b to jump back to the bookmark, the fringe mark will be again shown on the fringe. The command C-x r M (bookmark-set-no-overwrite) works like C-x r m, but it signals an error if the specified bookmark already exists, instead of overwriting it. To display a list of all your bookmarks in a separate buffer, type C-x r l (list-bookmarks). If you switch to that buffer, you can use it to edit your bookmark definitions or annotate the bookmarks. Type C-h m in the bookmark buffer for more information about its special editing commands. When you kill Emacs, Emacs saves your bookmarks, if you have changed any bookmark values. You can also save the bookmarks at any time with the M-x bookmark-save command. Bookmarks are saved to the file ~/.emacs.d/bookmarks (for compatibility with older versions of Emacs, if you have a file named ~/.emacs.bmk, that is used instead). The bookmark commands load your default bookmark file automatically. This saving and loading is how bookmarks persist from one Emacs session to the next. If you set the variable bookmark-save-flag to 1, each command that sets a bookmark will also save your bookmarks; this way, you don't lose any bookmark values even if Emacs crashes. The value, if a number, says how many bookmark modifications should go by between saving. If you set this variable to nil, Emacs only saves bookmarks if you explicitly use M-x bookmark-save. The variable bookmark-default-file specifies the file in which to save bookmarks by default. If you set the variable bookmark-use-annotations to t, setting a bookmark will query for an annotation. If a bookmark has an annotation, it is automatically shown in a separate window when you jump to the bookmark. Bookmark position values are saved with surrounding context, so that bookmark-jump can find the proper position even if the file is modified slightly. The variable bookmark-search-size says how many characters of context to record on each side of the bookmark's position. (In buffers that are visiting encrypted files, no context is saved in the bookmarks file no matter the value of this variable.) Here are some additional commands for working with bookmarks:

M-x bookmark-load RET filename RET
Load a file named filename that contains a list of bookmark values. You can use this command, as well as bookmark-write, to work with other files of bookmark values in addition to your default bookmark file.
M-x bookmark-write RET filename RET
Save all the current bookmark values in the file filename.
M-x bookmark-delete RET bookmark RET
Delete the bookmark named bookmark.
M-x bookmark-insert-location RET bookmark RET
Insert in the buffer the name of the file that bookmark bookmark points to.
M-x bookmark-insert RET bookmark RET
Insert in the buffer the contents of the file that bookmark bookmark points to.
Manual
Emacs 31.0.90
Texinfo Node
Registers
Source Ref
emacs-31.0.90
Source
View upstream