The Code pasted into Vim from other editors is often incorrectly formatted due to abnormal indentation. Found in Vim's official FAQ (http://vimdoc.sourceforge.net/cgi-bin/vimfaq2html3.pl: Format full text: Gg = G Auto indent current row: = This is an excerpt from the original article: 14.6. How do I Format/indent an entire file?
You can format/indent an entire file using the GG = g command, where
GG-goto the beginning of the file =-Apply indentation G-till end of File
For more information, read
: Help gg : Help = : Help g : Help 'formatprg' : Help C-indenting |
|
Original article addressHttp://hi.baidu.com/seesea8/blog/item/b96c8e51eb8f352743a75b41.html |
Conversion:
Recently, when I visit csdn forums, I often have a problem-some users do not post the code in a standard format, and I often need to manually adjust the format when I post it to VIM, which is very troublesome. At this time, I miss the Alt + F8 ...... Think of VIM as the most intimate editor for programmers, and obviously won't ignore it. After some searching, I found some of the most commonly used simple skills and took notes for future use.
Vim format code:
Format full-text command Gg = G
Auto indent current line command =
Format the next 8 rows of the current cursor.
Format the selected row v select the code segment to be formatted =
Note:
Gg -- arrive at the beginning of the file
= -- Requires indentation
G -- until the end of the file
Code annotation: (this principle is to use Vim's regular expression replacement)
Take C ++ and python as examples.
Comment row:
Command Format: start line,Terminate a rowS/Character to be replaced/Replace with character/G
For example,
Comment out 10 ~ in the C ++ source file ~ 20 lines, command:
: 10, 20 s/^ // G
Comment out 10 ~ In the Python source file ~ 20 lines, command:
: 10, 20 s/^/#/g
Cancel comments of consecutive rows:
The command format is the same as above. Only replacement characters and replacement with characters must be exchanged:
For example,
Cancel 10 ~ 20 lines of comments. The command is:
: 10, 20 s/^ ///g
Cancel 10 ~ 20 lines of comments. The command is:
: 10, 20 s/^ # // G
SELF: http://blog.csdn.net/ph123456789/article/details/6369018