To explain the use of register, let's look at the normal cut-copy-pasting of text first. When you have cut or copied some text, it lives in a place we call the clipboard, from with you can then paste it. But in most programs, if you copy/cut text again, it replaces what was already on the clip board.
Now, what about registers? In emacs, we have a special clipboard with multiple places to store things, each named by a single number or letter. We call these places registers. Thus, you can save some text to register A, some other text to register B, and later paste the contents of register A or B. The key bindings (shortcuts) for this are good to remember:
|C-x r s R||save region (selection) into register R|
|C-x r i R||insert the contents of register R|
(Note: the clipboard that emacs uses for 'normal' cut/copy/paste, the 'kill-ring', allows for multiple (but unnamed) entries as well - but we'll discuss the kill-ring in some other entry.)
viewing register contentsOne obvious problem with registers is that for most people it's very hard to remember what went into which register, if you use more than two or three registers. There is M-x view-register, but that's only marginally useful. It would be much nicer if we could get a list of all registers in use and a preview of their contents. To do that, we can use the list-register.el package (see installing packages). The package adds a function list-registers (and some others). I use a key binding C-x r v for that, which somewhat logically follows the other ones:
|C-x r v||view registers|
(require 'list-register) (global-set-key (kbd "C-x r v") 'list-register)An alternative would be to use C-x r l (for list registers), but that one has already been taken by bookmark-bmenu-list, which shows a list of your bookmarks -- to be discussed some other time).
I would vote for including the list-registers functionality in emacs. Having registers without a way to view them, makes them much less useful.
more than wordsPersonally, I seldomly use registers for anything but text; however, you can store other things in registers as well (see the Emacs Manual registers section for details):
|rectangle||C-x r r R||C-x r i R||save rectangle into register R (see working with rectangular selections, and insert it);|
|buffer/position||C-x r <SPC> R||C-x r j R||save buffer/position in register R, and jump back to it|
|window||C-x r w R||C-x r j R||save window configuration in register R, and jump back to it. Note that what emacs calls a window is called a window pane elsewhere, see emacs terminology)|
|frame||C-x r f R||C-x r j R||save frame configuration in register R, and jump back to it. Note that what emacs calls a frame is called a window elsewhere, see emacs terminology|
While registers are quite useful, I think they would be easier to use if they were integrated with the normal cut-copy-paste (the 'kill-ring'). Another issue is that you cannot access your registers from other programs. Actually, recent MS-Office versions do this in a bit nicer way...