Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim regex increment all numbers by 1

Tags:

regex

vim

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.

like image 313
user606723 Avatar asked May 02 '12 20:05

user606723


2 Answers

Figured it out.

%s/\d\+/\=(submatch(0)+1)/g 

http://vim.wikia.com/wiki/Using_an_expression_in_substitute_command

like image 177
user606723 Avatar answered Sep 18 '22 05:09

user606723


The only regex you need to know is \d.

:g/\d/exe "normal! \<C-A>" 
like image 30
gpojd Avatar answered Sep 21 '22 05:09

gpojd