Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

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.

like image 529
kartik Avatar asked Dec 04 '22 10:12

kartik


1 Answers

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;

like image 190
Birei Avatar answered Apr 24 '23 21:04

Birei