I want to comment all lines that match a particular string. I am doing assembly programming, so lines are commented using ";" character.
The string (pattern) may be present anywhere within the line. The comment should be added to the beginning of the line (obviously).
Using the up and down arrow key, highlight the lines you wish to comment out. Once you have the lines selected, press the SHIFT + I keys to enter insert mode. Enter your command symbol, for example, # sign, and press the ESC key. Vim will comment out all the highlighted lines.
To comment out multiple code lines right-click and select Source > Add Block Comment. ( CTRL+SHIFT+/ )
For commenting a block of text is almost the same: First, go to the first line you want to comment, press Ctrl``V , and select until the last line. Second, press Shift``I``#``Esc (then give it a second), and it will insert a # character on all selected lines.
Method 1: Using <<comment: In Shell or Bash shell, we can comment on multiple lines using << and name of comment. we start a comment block with << and name anything to the block and wherever we want to stop the comment, we will simply type the name of the comment.
Alternatively:
:g/pattern/s/^/;
I'd say
:g/pattern/norm I;
(assuming ;
is the comment character, and pattern
is what you're looking for)
See also: |I|
in insert.txt
docs
:s
command add a ;
to the beginning of each matched line:
:%s/.*pattern/;&
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With