问题
I have a prepared statement in java that i am adding an argument to the front of. Long story short, I have to take a ton of set methods and increment their first argument by 1.
I'd like a quick way to do a search and replace matching all numbers, and then increment them by one.
回答1:
Figured it out.
%s/\d\+/\=(submatch(0)+1)/g
http://vim.wikia.com/wiki/Using_an_expression_in_substitute_command
回答2:
The only regex you need to know is \d.
:g/\d/exe "normal! \<C-A>"
回答3:
I mis-interpreted the question as to be asking how to increments a number by one on each line, i.e.
var1
var1
var1
to be
var1
var2
var3
So I thought I'd post an answer for that. The link @user606723 provided shows that you can do that with (say between lines 1 and 3):
:let counter=0|1,3g//let counter=counter+1|s/^/\=counter."\t"
来源:https://stackoverflow.com/questions/10420797/vim-regex-increment-all-numbers-by-1