There are some situations while working in vim to add/delete/replace some keywords/lines based on matched pattern. Like remove ^M from a file and we explained various methods to do so.
User may face few other situations where they can use vim commands like %s or :g efficiently.
Find a pattern globally and delete the matched lines
Ex: Delete all lines which matches “No match” in a file
- Delete all blank lines from a file
- Delete lines which have one or more spaces only
[vim]:g!/\S/d or v/\S/d
Delete all lines which doesn’t match the pattern
Delete all lines except lines which have the ‘2013-10-29’ date format in the line
- Copy all lines matching a pattern to end of file.
- Move all lines matching a pattern to end/top of file.
I hope it will solve another vim users problem in their day-to-day activities.
Latest posts by Sanjeev Jaiswal (see all)
- Possible ways to hack mail account - April 5, 2016
- Hiding sensitive header response for IIS server - March 17, 2016
- First Android App reached 2 million downloads says Ankit Srivastava - February 29, 2016