Reprint of the http://blog.csdn.net/king_on/article/details/8104235
Declaration of this digest from the network, the initial author is not clear, so did not leave the original link. If anyone knows, please tell them.
Vim is one of the best text editors to use Vim to document, writing code is really a pleasant thing. Whenever you learn a new function of vim, it will greatly improve the efficiency. The use of vim for decades has not yet fully mastered the functionality of Vim, which also illustrates the power of vim. And this is not a good thing, as long as some study, there are improvements.
The recent use of vim to write a blog, found in vim after pasting Python code, indentation is completely chaotic. Careful study of the following, the original is automatically indented for the sake of, so do the following settings:
: Set Noai Nosi
Auto indent and Smart indent are canceled, so the paste will not go wrong. But in some vim does not work, or typesetting disorder.
Later found a better use of the settings:
: Set Paste
After entering paste mode, you can paste the content in insert mode without any distortion. This is really gray often easy to use, can't help but look at the help, found that it did so much: TextWidth set to 0 Wrapmargin set to 0 sets Noai setting Nosi Softtabstop set to 0 revins reset ruler reset Showmatch resetting formatoptions using null values
The following option values are not changed, but are disabled: Lisp indentexpr cindent
No wonder before only set Noai and Nosi not, originally with so many factors related.
But this is still more troublesome, each time to paste, the first set paste, and then paste, and then set Nopaste. There is no more convenient. You may have thought of it, using a keyboard mapping Yes, yes. We can set this::
: Map <F10>: Set paste<cr>
: Map <F11>: Set nopaste<cr>
So before pasting press F10 key to start paste mode, paste and press F11 cancel paste mode. In fact, paste has an option to toggle the paste switch, which is pastetoggle. It allows you to bind shortcut keys to activate/deactivate paste mode. Like what::
: Set pastetoggle=<f11>
This reduces the use of a shortcut key, which is more convenient.
But, this is the most convenient. Vimer The pursuit of efficiency is endless. Is there any better way to do it.
You may have thought of the VIM register. Yes, use the VIM register "+p paste." There is no need to consider whether automatic indentation, whether paste mode, direct text delivery. :
"+p
To say vim registers, from the vim file between the copy and paste speaking.
In vim, to copy the current line, press yy in normal mode and press p where you want to paste. This is why vim saved the copied content to its own register. If YY is executed elsewhere, the new content will overwrite the contents of the original register. If you want to save the contents of the original register and add new content at the same time. This is the time to add tags before yy. The label starts with double quotes, followed by the label name, either the number 0-9, or 26 letters, and then the copy operation, which saves the copied content to the tag register. All register contents are displayed by the following command:
: Reg
Note Two special registers: "* and" +. These two registers are communicated with the system, the former relates the system selects the buffer, the latter relates the system Shearing board. They can be used to exchange data with other programs. Note:
If there is no "* or" + Register in the Register list, it may be caused by the lack of a graphical interface to install VIM. Debian/ubuntu can be resolved by installing the vim-gnome.
$ sudo apt-get install Vim-gnome
Choose what the difference is between the buffer and the system Clipboard. Let's continue our research. Select buffer and clipboard
Unlike the Windows,linux system, there are two shear plates: one is called the selection buffer (X11 selection) and the other is the shear plate (clipboard).
The selection buffer is real-time, and when you select content with the mouse or keyboard, the content already exists in the selection buffer, which is probably the origin of the selection buffer.
Use the following command to view the contents of the selection buffer:
$ xclip-out
If there is no Xclip command, Debian/ubuntu can be installed under the following command:
$ sudo apt-get install Xclip
You can use the middle mouse button or type Shift+insert to paste the contents of the selection buffer. However, for some GUI programs, such as Gedit, can only be called by the middle mouse button to select the contents of the buffer, the use of Shift+insert, the call is the content of the Clipboard.
The Clipboard is similar to the Clipboard in Windows, where the content is stored in the Clipboard after selecting the text, executing CTRL + C or selecting ' Copy ' in the menu.
Use the following command to view the contents of the Clipboard:
$ xclip-out-sel Clipboard
Instead, the contents of the Clipboard are CTRL + V. However, in some cases, such as gnome-terminal, can not directly use the CTRL+C,CTRL+V, this time will be replaced with Shift+ctrl+c,shift+ctrl+v. paste in original format
Okay, here's the selection buffer and the Clipboard, here is the perfect solution for preserving formatting paste: Scenario One: Select text content vim Normal mode press "*p to paste the contents of the selection buffer into the Scheme II: Copy the contents of the file in vim Normal mode press" + P paste the Clipboard contents into
At this point, if the content to be copied is also the content in the Vim editor, then how to copy is more convenient. replication in Vim
Vim has a visual mode that allows you to select regions in this mode. You can type V into visual mode in normal mode, or you can personalize it by typing V into the line visual mode, or by typing CTRL + v. into the column visual mode. You can then move the cursor to select the content. Note that the selection is saved in real time in the selection buffer, and of course you can also type "+y to save this content to the Clipboard, or" Ay "to save the content to a register labeled a. But you know, only the first two of the content can be used in other programs, and the contents of a register can only be used within the VIM editor.
You can also copy them with the mouse. Here you first turn on mouse mode. :
: Set Mouse=a
This allows you to copy to the selection buffer directly using the mouse selection area in normal mode. However, this situation cannot be copied to the Clipboard.
To copy content to the clipboard using your mouse, you need to set the following:
: Set Mouse=v
In this case, in addition to being able to copy to the selection buffer directly using the mouse selection area as above, you can also select "Copy" in the context menu to save to the Clipboard. But the new problem came out again. If the line number is displayed, the line number is also selected. You will think, this is good, if you do not need a line number, before copying, first execute the set Nonu to suppress the line number display chant.
In fact, there is no need to do so, if you do not need to copy the line number, use in the visual mode with the keyboard to choose not to do it.
And, from the discussion above, it is not difficult to conclude that using a selection buffer is much more convenient than using a clipboard, which can save a lot of steps.
So, finally we got the perfect scheme for copying and pasting vim files, the transfer of files using the selection buffer. The perfect solution for copying and pasting between vim files
In ~/.VIMRC, add the following line:
Set Mouse=v
Copies the content to the selection buffer. With line numbers, use the mouse to select the content area. Do not line numbers, use "*yny" to copy n rows or select in Visual mode.
Paste the contents of the selection buffer into the vim file: press *p in normal mode.