Http://www.21andy.com/blog/20100413/1859.html
Vim Annotation Multiline Simplified description
The following comment 3 line operation is as follows ESC
0 jump to the beginning of the line
Ctrl + V Visual block mode
JJJ Move Down 3 lines
I go into insert mode
//
ESC or Multiline uncomment Ctrl + V, and then select the Comment column for the line you want to reverse, and then D to delete.
It's too much trouble to define shortcut keys yourself # vim ~/.VIMRC
Enter the following to save the F5 for comment
Vmap <F5>: s=^\ (//\) *=//=g<cr>:noh<cr>
Nmap <F5>: s=^\ (//\) *=//=g<cr>:noh<cr>
IMAP <F5> <esc>:s=^\ (//\) *=//=g<cr>:noh<cr>
"F6 for Uncomment
Vmap <F6>: s=^\ (//\) *==g<cr>:noh<cr>
Nmap <F6>: s=^\ (//\) *==g<cr>:noh<cr>
IMAP <F6> <esc>:s=^\ (//\) *==g<cr>:noh<cr>
Vim Annotation Multiline detail:
Ctrl + V enters the column mode, moves the cursor down or up, marks the beginning of the line that needs to be commented on, then presses the uppercase I, inserts the annotation character, such as #, and then presses ESC, and then all comments. Or you can run the following commands::s/^/# #用 "#" note the current line
: 2,50s/^/# #在2 ~50 The beginning of the line add "#" note
:.,+3s/^/# #用 "#" note three lines after the current line and the current line
:%s/^/# #用 "#" Note all rows
By the way, Vim's replacement, this common, it has been kept in mind that, in fact, it is the same as the above with command annotations, except that the "^" symbol in the note above indicates the start position, and in the following commands, "S" represents the replacement, the part1 represents the content of the lookup, and the part2 represents the replacement. % "represents all rows, and" G "replaces all content in the entire line (if not"/g "replaces only the first matching part1 of each line). : S/part1/part2 #用part2替换当前行中第1个part1
: s/part1/part2/g #用part2替换当前行中所有的part1
:%s/part1/part2 #用part2替换所有行中每行第1个part1
:%s/part1/part2/g #用part2替换所有行中所有的part1
: 2,50s/part1/part2 #用part2替换第2行到第50行中每行第1个part1
: 2,50s/part1/part2/g #用 Part2 replaces all part1 in lines 2nd through 50th
:., +3s/part1/part2 #用part2替换当前行以及当前行后面的三行中每行第1个part1
:., +3s/part1/part2/g #用part2替换当前行以及当前行后面的三行中所有的part1
BTW: When replacing, be aware that some characters need to be translated, such as spaces, parentheses, and so on.