"Vim little" vim's copy and paste (including system clipboard)

Source: Internet
Author: User

1. Vim Common copy and Paste command


Vim's copy-paste command is undoubtedly y (Yank), p (paster), plus yy,p


Ps:

Vim has a very interesting convention (I think it is a convention), that is, the case of a command is to achieve a certain function, but the direction is different, such as:

W Jump to the next word,w: Jump to the last WORDF  a line forward to find and jump    F: Reverse ....

Then some double-written letters have line operations:

YY   Copy line dd   Delete Row

So

P is pasted after the current cursor and p is pasted before the current cursor


In addition, there are several commands that are sometimes useful when you finish p.

GP, and P function basically consistent, just paste, it will move the cursor after the paste content; GP similarly: pu[t], note that this is the command interface input pu/put, it means to paste the contents of the X register to the next line


2. Vim Registers and system Clipboard
Introduction to Registers

One of the great features of vim is that it comes with a stack of registers, each of which is used independently, you can store different data in different registers, commands, you can think of this as a strong version of the Clipboard, of course, its function is more than the Clipboard so simple. If you want to see the official documentation about VIM section:

: Help  Registers


According to the Official Handbook: Vim has 9 types of registers

There is nine types of registers:registers E354
1. The unnamed register ""
2. Numbered registers "0 to" 9
3. The small delete register "-
4. Named registers "A to" Z or "A to" Z
5. Four read-only registers ":,"., "% and" #
6. The expression Register "=
7. The selection and drop registers "*," + and "~
8. The Black hole Register "_
9. Last Search pattern Register "/


1. Nameless (unnamed) Register: "", cache the last action content;

2. Digital (numbered) register: "0 ~" 9, cache the most recent operations, copy and delete, "0 register cache last copied content," 1-"9 cache the last 9 times deleted content

3. In-line Delete (small delete) Register: "-, cache in line delete content;

4. Named (named) Register: "A ~" Z or "A-" 0Z, available when specified;

5. Read-only (read-only) Register: ":,"., "%," #, respectively cache the most recent command, the most recently inserted text, the current file name, the current alternate file name;

6. Expression Register: "=, read-only, used to execute an expression command;

7. Select and drag (selection and drop) Register: "*," +, "~, Access GUI Select text, can be used to interact with external applications, using the prerequisite for the system Clipboard (clipboard) available;

8. Black Hole Register: "_, do not cache the contents of the operation (clean delete);

9. Mode register (last search pattern): "/, caches the most recent search mode.

As for the more specific use of each register, I hope that you can check the manual, after all, this article is not the focus of the register, maybe one day will write a small note about register it


Basic operations

Talking about the basic operation of the Register

Now enter the command, you can query the current register of the situation

: Reg

The use of registers is also simple: by "plus the register name, you can access a specific register:

"AP      paste Letter A register content" 1y      copy selection to digital Register 1


system Clipboard

Careful people have found my key to the register part, that is the selection and drag the register, this is the system's clipboard, we usually use the CTRL + V content is stored in the register, so you want to copy the content in the + register, can be pasted in the GUI interface or CTRL + V paste, the same, paste in Vim is also the same

"+y    Copy to system Clipboard" +p    paste "+gp  paste and move cursor to paste content


But just enter the command "+p is already very troublesome, this time, the map function of Vim can be prowess again, we only need to" +y and "+GP Map to your favorite shortcut keys can:

First Open VIMRC (if not, create one)

Vim ~/.VIMRC

Then enter it in:

Nmap <c-v> "+gpnmap <c-c>" +y

You can now use CTRL + C and CTRL + V,but! I personally do not recommend this shortcut key, because itself <c-v> is my very common block command

So, I generally modify it into:

Nmap <leader>v "+gpnmap <leader>c" +y

As for the <leader> is what button, you can follow your preferences to pull, my is ', '

Let mapleader= ","


Ps. To say, I use Nmap, indicating that this command only in normal circumstances only effective, in the Insert mode is not effective, why do you want to set it? Because sometimes you really need to input <leader>c/v content, for example, C, V, and, vim main operation I think it should be in normal mode, this is the reason for vim's efficiency.

"Vim little" vim's copy and paste (including system clipboard)

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.