Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the solution to vim's code format indentation from copy on the Internet?

Shulou Source: shulou.com Published: 2022-06-01 17:19:08 10月03日 Update

Today, I will talk to you about what is the solution to the random indentation of the code format of vim from the online copy. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Sometimes when you copy and paste the code from the editor into vim, the format of the code is completely out of order. The reason for this is that vim turns on smartindent (Smart reduction) or autoindent (automatic alignment) mode. To maintain the format of the code, you can stop the above two modes before pasting, the command is:

Set nosmartindentset noautoindent

The above command is to type a colon (:) in vim's read mode, and then execute it separately. It's really troublesome to do so many things for a paste. However, there is an easier way to start paste mode with the command, that is:

Turn on set paste and close set nopaste or set paste!

Since the paste mode and the above smartindent and autoindent modes are mutually exclusive, and smartindent is indispensable, use one of the two commands above to turn off paste mode after pasting.

You can also quickly switch by binding custom shortcuts, such as adding subordinate configurations to .vimrc

Method 1:set pastetoggle= way 2::map: set paste:map: set nopaste

Note: mode 1 can be used in both read and edit modes, switching paste mode on and off; mode 2 is used in read mode, and pressing the corresponding shortcut key is equivalent to executing the command defined later.

After reading the above, do you have any further understanding of the solution to the code format indentation that vim copy down from the Internet? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Mode code command mode format method content facet shortcut key is in switch multitasking one colon reason can be passed intelligence more sometimes knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia vpn Docker Shulou Information MariaDB