Reputation: 5500
I need a vim command for deleting all characters before a particular word for all the lines in a file
Ex: Input:
asdfasdfasdfscccHello
qwerqwerHello
24351243vsfgertHello
Output:
Hello
Hello
Hello
Upvotes: 22
Views: 33816
Reputation: 15300
If you want to delete all characters before "Hello", you can do
:%s/.*Hello/Hello/
Note that .*
is greedy, i.e. it will eat all occurrences of "Hello" till it finds the last one. If you have a line:
abcHellodefHelloghi
it will become
Helloghi
If you want a non-greedy solution, try
:%s/.\{-}Hello/Hello
Upvotes: 52