Reputation: 141160
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?
Upvotes: 2
Views: 228
Reputation: 685
Hmm, I think you can get it working with:
:%s/^\(.*pdf\)/#\1/
or if you want to prepend '%' instead of '#':
:%s/^\(.*pdf\)/%\1/
Upvotes: 4
Reputation: 881625
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).
Upvotes: 9