Vim copy and paste explores Vim as one of the best text editors. Using vim to compile documents is really cool to 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. This also shows vi... vim copy and paste explores Vim as one of the best text editors. Using vim to compile documents is really cool to 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. Www.2cto.com recently used Vim to write a blog and found that after the Python code is pasted in Vim, the indentation is messy. After carefully studying the following, it turns out to be auto indent, so we made the following settings: set noai nosi removes Auto Indent and smart indent, so that the paste will not be wrong. But in some vim, the layout is still disordered. Www.2cto.com later found a better setting: After set paste enters the paste mode, you can paste the content in the 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: textwidth is set to 0 wrapmargin is set to 0 set noai set nosi softtabstop is set to 0 revins reset rmatch reset showmatch reset formatoptions the value of the option below the null value remains unchanged, but is disabled: lisp indentexpr cindent no wonder it's not possible to set only 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 it as follows: map : Set paste : Map : Set nopaste 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 = 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 say 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 copied 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" + register, 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 the buffer and the system clipboard? Let's continue our research. The selection buffer and clipboard are different from those in Windows. in Linux, there are two clipboard: one is the selection buffer (X11 selection buffer), and the other is the clipboard (clipboard ). The selection of the buffer zone is real-time. when you use the mouse or keyboard to select the content, the content already exists in the selection buffer zone. This may be the way to select the buffer zone. Run the following command to view the content of the selected buffer: $ xclip-out. if there is no xclip command, run the following command in Debian/Ubuntu to install the buffer :: $ sudo apt-get install xclip can be used to paste the content of the selected buffer by typing Shift + Insert in the middle mouse. However, for some GUI programs, such as gedit, the content of the selection buffer can only be called by the middle mouse. if Shift + Insert is used, the content of the clipboard is called. The clipboard is similar to the clipboard in Windows. After you select the text content, press Ctrl + c or select 'copy' in the menu to store the content in the clipboard. Run the following command to view the clipboard content: $ xclip-out-sel clipboard and Ctrl + v. However, in some cases, for example, gnome-terminal, you cannot directly use Ctrl + c, Ctrl + v. In this case, Shift + Ctrl + c, Shift + Ctrl + v should be used instead. After pasting the original format, I learned about the selection of the buffer zone and Clipboard. The following is a perfect solution for retaining format pasting: Solution 1: select text content in vim normal mode and press "* p" to paste the content in the selection buffer. Solution 2: copy the file content in vim normal mode and press "+ p to paste the clipboard content, if the content to be copied is also in the vim editor, how can it be copied more conveniently? Copy vim in vim has a Visual Mode in which you can select a region. You can type v in normal mode to enter the visual mode, or you can personalize it. Type V to enter the line visual mode, or press Ctrl + v to enter the column visual mode. Move the cursor to select the content. Note that the selected content has been saved in the selection buffer in real time. you can also type "+ y" to save the content to the clipboard, or "ay" saves the content to the register labeled as. But you must know that only the content in the first two can be used in other programs, and the content in register a can only be used in the vim editor. You can also copy it with the mouse. The mouse mode must be enabled first.: Set mouse = a in normal mode, you can directly use the mouse to select a region and copy it to the selection buffer. In this case, the clipboard cannot be copied. To copy the content to the clipboard with the mouse, you need to make the following settings: set mouse = v. In this case, you can copy the content to the selected buffer using the mouse selection area as above, you can also choose copy from the shortcut menu to save it to the clipboard. However, new problems have emerged. If the row number is displayed, the row number is also selected. You will think, this is easy to do. if you do not need a row number, execute set nonu before copying to cancel the row number display. In fact, this is not necessary. if you do not need to copy the row number, you can use the keyboard to select it in visual mode? In addition, from the above discussion, it is not difficult to conclude that using the selected buffer zone is much more convenient than using the clipboard, which can save a lot of steps. Therefore, we finally got the perfect solution for copying and pasting vim files, and used the buffer zone for transferring files. The perfect solution for copying and pasting vim files is ~ /. Add the following line to vimrc: set mouse = v copy the content to the selection buffer. When a line number is included, use the mouse to select the content area. Do not use line numbers. use "* yny to copy n rows or select in visual mode. Paste the content in the selection buffer to the vim File: In normal mode, press "* p. Supplement: in vim, the default selection buffer register "*: set clipboard = unnamed can be used to exchange data directly through y, p and the system selection buffer.
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.