Vim paste code format is scrambled

Source: Internet
Author: User

Sometimes you copy and paste code from the editor into Vim, and the code format is completely messed up. The reason for this is that vim turns on smartindent (smart reduction) or autoindent (auto align) mode. In order to maintain the format of the code, you can first stop the above two modes before pasting, the command is:

Set Nosmartindentset noautoindent

The above command is to enter a colon (:) and then execute it separately in Vim's reading mode. It is really troublesome to get so much out of a paste. However, there is a simpler way to start the paste mode with a command, namely:

Turn on set paste close set Nopaste or set paste!

Because the paste mode and the above smartindent, autoindent mode is mutually exclusive, and smartindent is not rare, so after pasting, use one of the above two commands to turn off paste mode.

You can also quickly switch by binding custom shortcut keys, such as adding subordinate configurations to the. VIMRC

Way 1:set pastetoggle=<f4> mode 2::map <F8>: Set paste:map <F9>: Set Nopaste

Note: Mode 1 can be used in both reading and editing modes to toggle paste mode on and off, Mode 2 is used in reading mode, and pressing the corresponding shortcut key is equivalent to executing the command defined later.

Vim paste code format is scrambled

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.