I can see a lot of discussion on how to replace strings conditionally using :%s. But I want to do exactly this in my file that has a huge bunch of numbers in a CSV format:
< -100-98How can I do this in VIM or any other editor/script language?
It is possible using the submatch() function like this:
:%s/-[0-9]\+/\=submatch(0) < -100 ? -98 : submatch(0)/g
Now every number smaller than -100 will be replaced by -98 and the rest just stays the same. Note that this regex will only match negative numbers.
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