Demand
C99 introduces the "//" single-line annotation method, so C and C + + are bouncing in comments!
For program apes often make "necessary" comments in the source code. To meet the special needs, such as debugging, code additions and deletions, and so on! Do this on a command-line basis without adding plugins and configuring Vim. Therefore, for other implementations this is no longer mentioned here!
Command implementation
Description: Because the command uses the '/' delimiter method of readability is poor, so here at the same time with the ': ' Delimiter command as a supplement, the user according to preference playable.
1. Single-line annotation method (//) Comment Line
- Cursor in current line
: s/.*/\/\/&/
: S:.*://&:
- Specify comment lines
: N,n s/.*/\/\/&/
: N,n S:.*://&:
where n is the line number to comment on.
Additional Information
S-replace command
. *-Match a whole line
\/\/-Escape of "//"
&-Represents a match, here is a whole line
2. Multiline annotation mode (/**/) Comment Line
- Cursor in current line
: s//\/*&*\//
: s:. :/&*/:
- Specify comment lines
: N, N s//\/*&*\//
: N, N S:. :/&*/:
where n is the line number to comment on.
Additional Information
S-replace command
. *-Match a whole line
\/*-Escape of "/*"
&-Represents a match, here is a whole line
*\/-Escape of "* *"
3. Single-line comment method (//) Comment code block
- Specify the line interval
: N, M s/.*/\/\/&/
: N, M S:.*://&:
Global interval 1,$ and%
- Specify a match interval
- In Visual line mode, select the code block that you want to comment on, and then execute
: s/.*/\/\/&/
: S:.*://&:
- Specify start and end locations in search mode
: G/^void fun1/.,/^int fun2/-1 s/.*/\/\/&/
: G/^void fun1/.,/^int fun2/-1 S:.*://&:
Additional Information
/^void fun1/. -The starting point of the function to be commented out
/^int fun2/-1-Function end point to be commented out, minus 1 lines in fun2
The same as the previous replace operation ibid.
Here fun* can be replaced by the corresponding code block beginning with the beginning of word and ending the beginning of Word
4. Multiline comment Mode (/**/) Comment code block
A single-line comment method (//) Comment code block mode is also applicable here! It is only the difference between///replaced with "/**/". Don't repeat it! But if you add/**/to each line in the commented-out code block, it doesn't seem to be authentic! Here's how to solve this problem.
Method: Place the cursor at the starting point of the commented code and execute the following command
- : s:.*:/* &: | g/end/-1 s:.*:&*/:
Additional Information
First step: Add left Comment "/*" at the top of the current line
Through the pipeline, go to the second step
The second step: global search to the end of the commented code is the End-1 text line end append the right comment "* *"
Step three:: Noh cancel the high display of vim! over! perfect!
Note: Multi-line annotations cannot be nested!
Vim/C + + Comment code