vim's pasteboard

1, vim commonly used copy and paste commands

 

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 capitalization of a command is to achieve a certain function, but the direction is different, such as:

[plain] view plain copy
  1. w jumps to the next word, W: jumps to the previous word  
  2. f Find a line forward and jump F: Reverse....  

 

Then some double-written letters have line operations:

 

[html] view plain copy
  1. yy copy a line  
  2. dd delete a line  

 

so,

[html] view plain copy
  1. p means to paste after the current cursor, P means to paste before the current cursor  



In addition, after saying p, there are actually several commands that are sometimes useful.

[plain] view plain copy
  1. gp has basically the same function as p, but after pasting, it will move the cursor to the pasted content; the same is true for gP  
  2.   
  3. :pu[t] , note that this is pu/put entered in the command interface, which 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 strengths of vim is that it comes with a bunch of registers. Each register is used independently. You can store different data and commands in different registers. You can think of this as an enhanced clipboard. Of course, its functions are not only Clipboard is so simple. If you want to see the relevant part of vim's official documentation:

[plain] view plain copy
  1. :help  registers  



According to the official manual: vim has 9 kinds of registers

There are nine types of registers:                      registers E354
1. The unnamed register ""
2. 10 numbered registers "0 to "9
3. The small delete register "-
4. 26 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. Unnamed register: "", cache the last operation content;

2. Numbered register: "0~"9, cache the latest operation content, copy and delete are different, "0 register caches the last copied content Content, "1-"9 caches the last 9 deleted contents

3. Inline delete (small delete) register: "-, cache deletes content in line;

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

5. Read-only register: ":,".,"%,"#, respectively cache the latest command, the latest inserted text, the current file name, the current alternate file name;

6. Expression (expression) register: "=, read-only, used to execute expression commands;

7. Selection and drop (selection and drop) register: "*,"+,"~, access GUI selection text, can be used to communicate with external Application interaction, the premise is that the system clipboard (clipboard) is available;

8. Black hole (black hole) register: "_, do not cache operation content (clean delete);

9. Pattern register (last search pattern): "/, cache Recent search patterns.

As for the more specific usage of each register, I hope you can check the manual. After all, the focus of this article is not on the register. Maybe one day, I will write a small note about the register.

 

Basic operation

Let's talk about the basic operation of the register

Now enter the command, you can query the current register status

[html] view plain copy
  1. :reg  


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

[html] view plain copy
  1. "ap paste the contents of the letter a register  
  2. "1y copy the selection to digital register 1  

 

system clipboard

Careful people have found that the part of the register that I focus on is the select and drag register. This is the system clipboard. The content of ctrl+c ctrl+v we usually use is stored in this register, so you need to Put the content that needs to be copied in the + register, you can paste it in the gui interface with paste or ctrl+v, and the same is true for pasting in vim

[html] view plain copy
  1. "+y copy to system clipboard  
  2. "+p paste  
  3. "+gp paste and move cursor after pasted content  



But just typing the command "+p makes people feel very troublesome. At this time, the map function of vim can show its magic again. We only need to map "+y and" +gp to your favorite shortcut keys Go to:

First open vimrc (if you don't have one, create one)

[plain] view plain copy
  1. vim ~/.vimrc  


Then enter in it:

[plain] view plain copy
  1. nmap <c-v> "+gp  
  2. nmap <c-c> "+y  


You can now use ctrl+c and ctrl+v, but! I personally do not recommend using this shortcut key, because <cv> itself is my very commonly used block command

So, I usually modify it to:

[plain] view plain copy
  1. nmap <leader>v "+gp  
  2. nmap <leader>c "+y  

As for what button <leader> is, you can pull it as you like, mine is ','

[plain] view plain copy
  1. let mapleader=","  

 

Ps. Let me tell you, I am using nmap, which means that this command only takes effect under normal conditions, and it does not take effect in insert mode. Why do you want to set it like this? Because sometimes you really need to enter the content of <leader>c/v, such as ,c ,v , and I think the main operation of vim should still be in normal mode, which is the reason for the efficiency of vim.

Copyright statement: The words of the blogger who have worked so hard to reprint it~ Please indicate it~ https://blog.csdn.net/hk2291976/article/details/42196559

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326174147&siteId=291194637