Replace end of line for lines that start with a particular pattern

懵懂的女人 提交于 2019-12-23 12:46:45

问题


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 command
A;: 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!