Vim paste code to appear garbled resolution method

Source: Internet
Author: User

Http://www.cnblogs.com/end/archive/2012/06/01/2531147.html


Vim as one of the best text editors, using vim to write documents, writing code is very pleasant things. Whenever you learn a new function of VIM, you will greatly improve your work efficiency. Some people use vim for decades, not fully mastering the function of Vim, which also shows the strength of vim. And this is not a good thing, as long as some learning, some improve.

Recently using Vim to write a blog, found in vim paste Python code, indentation is completely messed up. Carefully studied the following, the original is automatic indentation, so do the following settings:

The automatic indent and smart indent are canceled so that the paste is not wrong. But in some vim is not good, or typesetting disorder.

Later found the better use of the settings:

After entering paste mode, you can paste content in insert mode without any distortion. This is really ash 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 set Noai sets Nosi Softtabstop set to 0 revins reset ruler reset Showmatch reset formatoptions Use null value

The following option values are unchanged, but are disabled: Lisp indentexpr cindent

No wonder before only set Noai and Nosi not, originally with so many factors.

But this is still relatively troublesome, each time to paste words, set paste, and then paste, and then set Nopaste. There is no more convenient to it. You might think, using a keyboard map, yes. We can set this::

This way before pasting press F10 to start paste mode, paste and press F11 to cancel paste mode. In fact, paste has an option to switch the paste switch, which is pastetoggle. It allows you to bind shortcut keys to activate/Cancel paste mode. Like what::

This reduces the use of a shortcut key and makes it easier to work with.

But is this the most convenient. Vimer's pursuit of efficiency is endless. Is there any other way to do it better?

You might think 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 transmission. :

To say vim registers, you need to copy and paste from the vim file.

In Vim, to copy the current line, press yy in normal mode and press p where you want to paste. This is the reason vim saves 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. At this point, we will add the label before YY. The label starts with a double quotation mark, followed by the label name, either the number 0-9 or 26 letters, then the copy operation, which saves the copy to the label register. Display all register contents by following command::

Note Two special registers: "* and" +. The two registers are connected with the system, the former is related to the system selection buffer, the latter is associated with the system shearing board. They allow you to exchange data with other programs. Note:

If there is no "* or" + Register in the Register list, it may be due to the absence of a graphical interface to install VIM. Debian/ubuntu can be solved by installing vim-gnome.

Select the difference between the buffer and the system Clipboard. Let's continue to study.

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.