Vim copy and paste
Vim, as one of the best text editors, uses Vim to compile documents and write code. Every time you learn a new feature of VIM, it will greatly improve productivity. Some people have been using Vim for decades and have not fully mastered the functions of VIM, which also shows the power of vim. But this is not a good thing. As long as you have some learning, you will have some improvement.
I recently used Vim to write a blog and found that after I pasted Python code in Vim, all the indentation became messy. After carefully studying the following, it turns out to be auto indent, so we made the following settings:
:set noai nosi
The automatic indentation and smart indentation are removed, so that the paste will not be wrong. But in some vim, the layout is still disordered.
Later, we found more useful settings:
:set paste
After entering paste mode, you can paste the content in insert mode without any deformation. This is really cool and easy to use. I can't help but read the help and find that it has done so many things:
- Set textwidth to 0.
- Wrapmargin is set to 0.
- Set noai
- Set nosi
- Set softtabstop to 0.
- Revins Reset
- Ruler Reset
- Reset showmatch
- Use a null value for formatoptions
The following options remain unchanged, but are disabled:
No wonder we can't set noai and nosi. It was originally related to so many factors!
However, this is quite troublesome. If you want to paste it, set paste first, paste it, and then set nopaste. Is it more convenient? You may have thought of using keyboard ing, right. We can set this as follows ::
:map <F10> :set paste<CR> :map <F11> :set nopaste<CR>
In this way, press F10 to start the paste mode, and press F11 to cancel the paste mode. In fact, paste has an option to switch the paste switch, which is pastetoggle. You can bind a shortcut key to activate or cancel the paste mode. For example ::
:set pastetoggle=<F11>
This reduces the usage of a shortcut key and makes it easier to use.
But is this the most convenient? Vimer's pursuit of efficiency is endless. Are there other good methods?
You may have thought of the vim register. Yes, use the vim register "+ P to paste it. You don't have to worry about automatic indent or paste mode. You can directly pass the original text! :
"+p
To talk about the vim register, we should start with copying and pasting between Vim files.
In Vim, to copy the current row, press yy in normal mode and p in the place to be pasted. This is why vim saves the copied content to its own register. If yy is executed elsewhere, the new content will overwrite the content in the original register. What if I want to save the content in the original register and add new content at the same time? In this case, we need to add a label before yy. The label starts with double quotation marks, followed by the tag name, which can be a number ranging from 0 to 9, or 26 letters, followed by a copy operation, in this way, the copy content is saved to the label register. Run the following command to display all registers ::
:reg
Note two special registers: "* and" +. These two registers are connected to the system. The former is associated with the System Selection buffer, and the latter is associated with the system clipboard. They can exchange data with other programs.
-
Note:
-
If the register list contains no "* or" + registers, it may be caused by the absence of the vim GUI. You can install vim-gnome In Debian/Ubuntu.
$ sudo apt-get install vim-gnome
What is the difference between a buffer zone and a system clipboard? Let's continue our research.