Vim Delete Words Without Matching
Vim Delete Words Without Matching
Ref: In Vim how to delete all words and characters not matching a pattern
1
:%s/\v(.*)(someting to match)(.*)/\2
\v
The “very magic” flag is useful for limiting the number of backslashes and improve legibility.
(.*)
The first group contains any number of any character. Anchoring to the start of the line is implied so it matches whatever is before what you want. It would be
\(.*\)
without the “very magic” flag.
This post is licensed under CC BY 4.0 by the author.