Problems related to vim code format pasting

Source: Internet
Author: User

Sometimes copy and paste the code from the editor to vim, and the code format will be completely messy. The reason is that vim has enabled the smartindent or autoindent mode. To maintain the code format, you can stop the above two modes before pasting. The command is:

Set nosmartindentset noautoindent

In vim's reading mode, enter the colon (:) and then execute them separately. It is indeed troublesome to create so many things for one paste. However, there is a simpler method to start the paste mode with the command:

Enable set paste to disable set nopaste or set paste!

Because the paste mode is mutually exclusive with the above smartindent and autoindent modes, and smartindent is indispensable, you can use one of the above two commands to disable the paste mode after pasting.

In addition, you can bind custom shortcut keys to quickly switch between them, for example, adding subordinate configurations to. vimrc.

Method 1: set pastetoggle = <F4> Method 2: map <F8>: set paste: map <F9>: set nopaste

Note: method 1 can be used in both reading and editing modes. You can switch between mode 1 and Mode 2 in reading mode, pressing the corresponding shortcut key is equivalent to executing the command defined later.


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.