On 2017-06-05 19:37, Erik Christiansen wrote:
> Both ^a and ^x have proven very useful in a variety of scenarios.
> Now, while editing some postscript, I sometimes have to decrement
> the magnitude of a series of literal constants by a common amount,
> and if there were mod variants of ^a and ^x, I'd be able to hit '.'
> on them all, instead of having to ferret out the positive ones,
> then go back for the negative, with all the scope for error which
> that entails.
While a side-stepping of your literal request, you can do
incrementing/decrementing in search replacements.
For all numbers in a range:
:'<,'>s/-\=\d\+/\=submatch(0)+22/g
to add 22 to all numbers in that range of lines. If you need more
context-aware targeting, you can use "\zs" and "\ze":
:'<,'>s/property=\zs-\=\d\+/\=submatch(0)+22/g
to only increment "property=###" by 22.
You can use any valid vim expression to the right of that
"\=" (though with a caveat regarding division, in which case I
recommend alternate delimiters:
:'<,'>s@-\=\d\+@\=(submatch(0)+22)/17@g
so that the "/" isn't seen as a delimiter for the :s command).
-tim
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Monday, June 5, 2017
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment