Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have the following SQL:

update am.PERMISSIONS set PRM_ORDER = 35 PRM_VISIBLE = b'1' where PRM_ID = 3;
update am.PERMISSIONS set PRM_ORDER = [35] PRM_VISIBLE = b'1' where PRM_ID = 7;
update am.PERMISSIONS set PRM_ORDER = [40] PRM_VISIBLE = b'1' where PRM_ID = 10;
update am.PERMISSIONS set PRM_ORDER = [45] PRM_VISIBLE = b'1' where PRM_ID = 11;
...

with square brackets I select the visual block, where i want to increase each number by 5. How do I do this?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Visually highlight the text in brackets:

Ctr+V2jl

Increment each number by five:

:norm 5Ctr+V Ctr+A Explanation:

:norm executes the whole command in normal mode. The Ctr+V is necessary, otherwise the cursor would jump back to the beginning of the line. Ctr+A increases a number by 1, and this is done 5 times. The visual range is inserted automatically after you pressed the colon.

EDIT: As Stephane correctly pointed out, the previous code increments the first number found on any line. Here's a better solution:

%s/\[\zs\d\+\ze\]/\=(submatch(0)+5)

It adds five to all integers within brackets. The \zs and \ze are used to exclude the brackets from the match and submatch returns the matched number.

share|improve this answer
    
It replaces the lines with -VC-A -VC-A -VC-A –  J-unior Apr 11 '13 at 10:23
1  
C-VC-A means press ctrl v, release, then press ctrl a, release. –  Marco Apr 11 '13 at 10:26
1  
That doesn't apply ^A on the visual selection, but at the start of every line marked by the selection (so for instance, if there were lines with numbers before the selected one, that would increase those and not the selected one) –  Stephane Chazelas Apr 11 '13 at 13:00
1  
You're totally right. It might work for the OPs use case, though. But I agree, my answer is wrong. –  Marco Apr 11 '13 at 13:12
1  
This plugin might be of some help to solve the problem, and I believe that if a plugin is necessary to do that kind of operations, it is not a simple matter of finding the right shortcut. –  Vincent Nivoliers Apr 11 '13 at 14:56
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.