VIM Editor: Delete Matched Search Pattern From A File
DELETE MATCHED SEARCH TERM FROM A FILE
Step1: Go to command mode and search mode
Step2: Now search for your term and replace it with nothing
:%s/searchterm//g
This will help you to delete all the occurrences of your search term. Let me explain above syntax
:%s is for searching for entire file, if you want to search in a particular line we can just use :s.
/serchterm// will replace ‘searchterm’ with nothing, which means it will be removed from that line
g for global removal, what it mean is the search and replace operation is applicable for all the occurrences of search-term in a given line.
DELETE MATCHED SEARCH TERM LINE FROM A FILE
Some times it’s require to delete entire line of your searched term. We can use below code once you go to command mode
:g/searchterm/d
DELETING REVERSE OR INVERSE OF SEARCH TERM LINES FROM A FILE
We can even delete all the lines which do not contain our search term with below code.
:g!/searchterm/d