VIM uses registers to copy and paste

Source: Internet
Author: User

You can now use most of Vim's basic commands, function to develop project code, but in the development process of the project, still feel some operation efficiency is low, for example through h/j/k/l to carry on the large-scale movement of the cursor this kind of operation, obviously vim provides more efficient command operation way. The most recent work that needs to be done is to copy, paste, search and replace the code back and forth, the commonly used d/y/x/p command is not enough, so I learned a bit of Vim's register function, using the content buffering function of register can greatly improve the efficiency of copying and pasting work. Register Type

VIM has 9 types of registers, the main function of the register is to delete, copy, search, and so on in the process of caching the text content, through: Help registers command to view the details of the register, here is the translation of the following types:

Unnamed registers ""--vim used by the default registers, Text Source command: d/c/s/x/y 10 digit named registers "0-" 9--vim Cache Yank and delete line operation command generated text 1 non-row delete content cache Register "---vim cache Delet E The text produced on a non-line 26-Letter named register "A-" z/"A-" z--full user-specified contents of the Register 4 read-only registers "." % "#": Expression Registers "=--uses Vim's powerful expression features (never used, not at all) GUI selection registers" * "+" ~--vim cached text black hole registers selected in GUI "_--similar to/dev/null files in Linux Out, which can be used to filter the content that affects the default registers. Last Search mode register "/--cache last search content used in vim

There are a lot of these registers, so how do you look at their content? Use VIM's: registers command or a shorter:d is command, which lists the contents of all existing registers, and then you can select the contents of the specified register to paste. Register Use

Notice that the name of the register is preceded by a double quote, which is the way to use them.

When you manipulate commands such as d/y/x in normal mode, you add the command-generated content to the specified register by adding the Register's name, such as "Ayy," in front of the command, as opposed to the "registers and" 0 registers that Vim uses by default. When pasting, insert the contents of the register into the line or bottom of the cursor, by adding the Register's name, such as an AP, before the P command.
Read-only registers, search-mode registers are put into content by vim, and users can only use their content.

Here are some of the registers that are more useful and familiar to individuals in development.

Digital Registers

"0: Stores the text content generated by the most recently used y command, if the content" 1-"9 is not explicitly specified: The text content generated by the recently used D-line operation command is stored, if the content is not explicitly specified, and the contents are rotated between 9 registers, that is, when there is new content," 1 of the content is pushed to "2, 2 to 3, 3 to 4 ... Letter Registers

If you're going to make multiple copies of a piece of content for a long time, it's best to use the letter registers, because their content will not be automatically modified by Vim, and the contents of the digital register will overwrite the content you specify as the new operation is used.

"A-" Z: Each time you specify one of these registers, the resulting text content will overwrite the contents "A-" Z in the Register: each time you specify one of these registers, the resulting text content is appended to the contents of the register, and if the value of the option ' Cpoptions ' has a > symbol, The append will be split at the same time, you can use the command:: Set cpo+=> settings. read-only registers

".: Contains the text content that was last inserted in vim insert mode, or you can pass the command. Repeat the last action. "%: Contains the name of the current file to facilitate inserting the file name" #: Contains the currently selectable file name, which refers to the name of the file used in the current session system Clipboard

The system Clipboard is used when copying content between multiple applications in the system, which can be used to paste content into vim using the "*," + registers, and they are all read-only registers. In addition, you can use the keyboard shortcuts Shift+insert to quickly insert.
Register Content Settings

In addition to specifying the contents of registers by adding a register number before the Operation command, VIM also provides a command to explicitly specify the contents of the register on the command line: let-@, such as the command: let @a = "Vim Registers blog", which means that the "a register content is set to the right value." Paste Mode

In Vim, you can set the Paste mode state by using the command: Set paste, at which point the pasted content will retain its original format; command: Set nopaste command to return to normal operation mode.


Original address: http://my.oschina.net/shelllife/blog/144357

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.