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