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
Immediately after opening a file, type “gg” to move the cursor to the first line of the file, assuming it is not already there. Then type dG to delete all the lines or text in it.
Shift + x is instead the appropriate command because was meant for that: Shift + x delete the previous character like Shift + p paste in the previous column.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With