Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To comment out matches in Vim

Tags:

vim

I would like to comment out each line which has the following match

^.*pdf

You need to somehow consider the situation by globbing. I try to make an object of the match by brackets.

I run unsuccessfully the following commands

%s/^(.*pdf)/^%$1/

and

%s/^(.*pdf)/^(%*$1)/

and

%s/^(.*pdf)/^%\$1/

How can you comment out the matches in Vim?

like image 513
Léo Léopold Hertz 준영 Avatar asked Dec 06 '25 17:12

Léo Léopold Hertz 준영


1 Answers

I'm not sure what you exactly mean by "comment out" (are comments indicated by hashes, or what?) but it looks like what you want is to prepend a % sign. In that case,

:g/pdf/s/^/%/

should work ("on all lines containing 'pdf', change the start of the line to a %" is how you could read it).

like image 58
Alex Martelli Avatar answered Dec 08 '25 09:12

Alex Martelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!