Back in September I wrote about using registers to open frequently accessed files. Shortly afterwards, someone recommended just saving my desktop with desktop-save-mode
and I haven’t really used registers since. More recently, I started watching Tim Visher’s excellent VimGolf in Emacs videos. Video #4 talks about, among other things, saving window/frame configurations in registers that you can then jump to. That caught my imagination so I looked into the use and abuse of registers some more.
As the name suggests, registers can hold various types of objects. They can hold
- Positions
- Text
- Rectangles
- Window and Frame configurations
- Numbers
- File names
Each register has a single character name by which it can be accessed. Thus a register could be named 1, or a, or A, or Ctrl-a. Only Ctrl-g is off limits for obvious reasons.
Now let’s take a look at how they can be used. First up is saving positions. This can be handy if you want to repeatedly refer to, say, a function in one of the buffers. To save a position in register ρ you would put the point at the position you want to save and type 【Ctrl+x r Space ρ】. To return to that position from the same or another buffer you would type 【Ctrl+x r j ρ】. This works even if the buffer containing the position has been killed providing the buffer was associated with a file.
You can copy or move a region into register ρ with the command 【Ctrl+x r s ρ】 and insert it at point with the command 【Ctrl+x r i ρ】. That’s how I inserted the rho (ρ) into the text—I looked it up once and then copied it into register r so I didn’t have to keeping going through the ucs-insert
routine.
If you give the 【Ctrl+x r s ρ】 command a prefix argument, it will delete the original region after copying it into the register.
There are two other less frequently used commands to store text to registers: 【Meta+x】 append-to-register
【Return】 ρ
and 【Meta+x】 prepend-to-register
【Return】 ρ
. These will append or prepend the region to the text already in register ρ. If you specify a prefix argument, the region will be erased after it is copied into the register.
You can copy a rectangle to register ρ with 【Ctrl+x r r ρ】 and insert it with 【Ctrl+x r i ρ】 as before. Just as with regions, specifying a prefix with the copy command will delete the original rectangle.
If you have a particular window configuration in the current frame your can save that configuration in register ρ with 【Ctrl+x r w ρ】 and you can later restore that configuration by jumping to it with 【Ctrl+x r j ρ】.
If you want to save the configuration of all frames and their windows in register ρ, use 【Ctrl+x r f ρ】.
Registers can also contain numbers. These numbers can be incremented, which make them useful for certain types of keyboard macros. To store N into register ρ, use 【Ctrl+u N Ctrl+x r n ρ】. To increment the number in register ρ by I use 【Ctrl+u I Ctrl+x r + ρ】.
You can insert the number in register ρ at point by using the usual insert command: 【Ctrl+x r i ρ】.
I’ve already dealt with storing file names in registers in the previous post linked above.
Summary
Key Sequence | Function |
---|---|
【Ctrl+x r Space ρ】 | Copy position to register ρ |
【Ctrl+x r j ρ】 | Jump to the position in register ρ |
【Ctrl+x r s ρ】 | Copy/Move region to register ρ |
【Ctrl+x r i ρ】 | Insert object in register ρ at point |
【Ctrl+x r r ρ】 | Copy/Move rectangle to register ρ |
【Ctrl+x r w ρ】 | Copy current frame configuration to register ρ |
【Ctrl+x r f ρ】 | Copy all frame configurations to register ρ |
【Ctrl+u N Ctrl+x r n ρ】 | Insert N into register ρ |
【Ctrl+u I Ctrl+x r + ρ】 | Increment register ρ by I |