When you look for source code from the Internet, you will often find that the code is well formatted, but with the line number in front, copy and paste it directly to remove the line number in front to compile, and worse, with the line number in front, the code is not typographical, which is a nightmare. This problem can be easily solved in vim.
Paste a piece of code on the Internet to VIM:
Figure 1 paste the online code to VIM
Is it pretty bad? Replace it with a regular expression (First: indicates the input mode)
: % S/[\ t] * \ D \ {1, 4 \}/
Immediately get the following results:
Figure 2 result after replacement
Now the effect is quite good, but there is still a problem, the indentation is incorrect, OK.
Go to the normal mode and run the following command ):
Gg jump to the beginning of the line
V enters visual mode
G to the end of the row
= Indent selected rows (all rows are selected here)
Whether the changes are immediately visible and all code is correctly indented.
The following is the indent result:
Figure 3 final effect after indent
Vim tips: remove the code line number and indent the code