问题
I have a file in the following format
--Some-XYZ-code ;
--Somemore--xyz--code;
COMMENT = " THIS IS A DEMO"
--somemore--code;
--somemore--code;
I want to put an semicolon at the end of line COMMENT, keeping the rest of the line intact.
回答1:
Try this:
:g/^COMMENT/ normal A;
For every line that matches COMMENT at the beginning enter in Insert Mode at the end of the line and append a semicolon.
Explanation: :g selects every line that matches following pattern ^COMMENT and does the action after last slash, normal A;
回答2:
This should do it:
:g/COMMENT/norm A;
g: globally on all lines matching /COMMENT/,norm: execute normal commandA;: of appending a semicolon to the end of the line.
回答3:
This should work
:%s/^COMMENT.*/&;/
来源:https://stackoverflow.com/questions/17826172/replace-end-of-line-for-lines-that-start-with-a-particular-pattern