Where do the registers come in?

Whenever you copy and paste text, it's saved in a register. Vim allows you to operate with many registers, which are identified by letters, numbers, and special symbols.

Registers can be accessed by hitting ", followed by the register identifier, followed for the operation on said register.

Registers a - z are used for holding manually assigned data. For example, to yank a word into the a register, you can run "ayw and paste it using "ap.

Registers are also used to record macros, which you will learn about in Chapter 6, Refactoring Code with Regular Expressions and Macros.

All of the operations you've performed so far have used the unnamed register. If you ever need to access the unnamed register explicitly, it is identified by a double quote character, ". For example, you can use ""p to paste from the unnamed register (which is the same as just invoking p).

Numbered registers are effectively a history of your last 10 delete operations. 0 accesses the last deleted text, 1 the one before it, and so on. For example, if you have stellar memory, you can paste some text you yanked seven yank operations ago by hitting "7p.

There are some read-only registers you might find handy: % holds the name of the current file, # holds the name of the previously opened file, . is the last inserted text, and : is the last executed command.

You can also interact with buffers from outside of a normal mode. Ctrl r is a convenient shortcut, which allows you to paste a register's contents when you're in insert or command-line modes. For example, while you're in insert mode, Ctrl + r" will paste the contents of the unnamed buffer at the position of the cursor.

You can access the content of a register at any time by running :reg <register names>. For instance, if you wanted to check what's inside the a and b registers, you'd run :reg a b. Here's the output:

In the preceding example, the a register contains def make_animal(kind):, and the b register contains a set of imports (from animals import ...) separated by newlines.

In addition, you can list the contents of every register by running :reg without any parameters.

Named registers (a-z) can be appended to as well. To append to a register instead of overwriting it, capitalize the register name. For example, to append a, word to register a, run "Ayw with a cursor at the beginning of the word.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.208.72