Vim Use series: Register and copy paste buffer

Source: Internet
Author: User

Transferred from: http://www.2cto.com/os/201307/227903.html

Vim Use series: Register and copy paste buffer

It is now possible to skillfully use most of Vim's basic commands and functions for Project code development, but during the development of the project, there are still some operational inefficiencies, such as the large-scale movement of the cursor through H/J/K/L, and it is clear that VIM provides a more efficient command operation. Recently often need to complete the work is the need to copy, paste, search and replace between the code, the commonly used d/y/x/p command is not enough, so learn the vim of the register function, the use of register content buffering function can greatly improve the efficiency of a large number of copy and paste work.

Register type
VIM has 9 types of registers, the main function of the register is to delete, copy, search and other text content during the cache operation, through: Help registers command to view the details of the register, the description of the type is translated as follows:

Unnamed register ""--vim default register used, text Source command: d/c/s/x/y
Text generated by 10 digit name register "0-" 9--vim Cache Yank and delete Row action commands
1 non-row deleted content cache register "---vim" the text produced when the cache delete operation is not on a line
26-letter-named register "A-" z/"A-" z--completely user-specified content register
4 read-only registers "." % "# ":
Expression Register "=--uses Vim's powerful expression function (never used, not understood)
GUI Select Register "*" + "~--vim cache text selected in GUI
Black hole Register "_--similar to the/dev/null file in Linux, can only be used to filter out the content that affects the default register.
Last search Mode register "/--cache the last search content used in vim
There are a lot of these registers, so how do you look at their contents? Using the VIM: registers command or a shorter:d is command, these two commands list the contents of all existing registers, and then you can choose to paste the contents of the specified register.

Register use
Notice that the names of the above registers have a double quotation mark in front of them, which is how they are used.

When you manipulate commands such as d/y/x in normal mode, by adding a register name such as "Ayy" in front of the command, the command-generated content is placed in the specified register, as in the a register above, rather than the "register and" 0 register that Vim uses by default.
When pasting, place the contents of the Register on or below the cursor location by adding the name of the register to the "AP" in front of the P command.
Read-only registers, search mode registers are placed into the content by vim, and users can only use their content.
Here are some of the registers that individuals feel will be more useful and familiar in the development of a specific description.
Digital Registers
"0: Contains the text content generated by the most recently used y command, if its contents are not explicitly specified
"1-" 9: Holds the text content generated by the most recently used D-line Operation command, if its contents are not explicitly specified, and the content is rotated between 9 registers, that is, when there is new content, "1 is pushed to" 2, 2 to 3, 3 to 4 ...
Letter Register
If you are going to copy a piece of content multiple times for a long time, it is best to use a letter register, as their content is modified by you and 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 one of these registers is specified, the resulting text content overwrites the contents of the Register
"A-" Z: Each time one of these registers is specified, the resulting text content is appended to the contents of the register, and if the value of the option ' Cpoptions ' has a > symbol, then the row is split at the same time, and can be set by the command:: Set cpo+=>.
Read-only Registers
".: Contains the text content that was last inserted in vim insert mode, and can also be ordered. Repeats the last action.
"%: Contains the name of the current file, which makes it easy to insert a file name
"#: Contains the currently selectable file name, which refers to the name of the file used in the current session
system Clipboard
When copying content between multiple apps in the system, the system Clipboard is used, which can be pasted into vim using "*," + registers, and they are also read-only registers. In addition, you can use the keyboard shortcut Shift+insert to quickly insert.
Register Content Settings
In addition to specifying the contents of the register by adding a register number before the action command, the VIM also provides a command to explicitly specify the contents of the register on the command line: [email protected], such as command: let @a = "Vim registers blog", means " A register content is set to the right value.

Paste Mode
In Vim, you can set the Paste mode state by command: Set paste, at which time the pasted content will be kept in the original format, and the command: Set nopaste command back to normal operation mode.

Vim Use series: Register and copy paste buffer

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.