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.