"Tim Chase" wrote,

Using a simple change to Tim Chase' original substitution response, you have:
[snip]
if you don't want to type it in every time,
:vmap <C-I> :s/\d\+/\=line('.')-line("'<")<CR>
which adds ctrl-i as a key in visual mode to do the job.

Ok, one last question on this. :-)

Is there a way to start this from where the cursor is and end with the first
non-matched instance? For example,

char[] str = null;

bla.blah.blahh[0].text;
bla.blah.blahh[0].text;
bla.blah.blahh[0].text;
bla.blah.blahh[0].text;
bla.blah.blahh[0].text;
bla.blah.blahh[0].text;

int i = 0;

bla.blah.blahh[0].text;
bla.blah.blahh[0].text;
bla.blah.blahh[0].text;
bla.blah.blahh[0].text;
bla.blah.blahh[0].text;
bla.blah.blahh[0].text;

So, if the cursor is on the first bla.* the first 6 lines will be numbered
sequentially and stop there.  Is this possible?

Well, if you have the above mapping, you can then map

:nmap <f4> vip<c-i>

which will visualize the block in question and then reduce the problem to the previously solved problem.

If you plan to then expand this to auto-numbering blocks throughout your your document, you might try something like (broken into multiple lines for easy reading, but would be all one mappable line)

:g/bla\.blah\.blahh\[\d/if getline(line('.')-1)=~'blah\.blah\.blahh\['
| let counter = 0
| endif
| s/blahh\[\zs\d\+/\=counter/
| let counter = counter + 1

I haven't tested it (so there's likely some escaping I got wrong), but it should do similar to my previous mapping, only when the previous line doesn't match the target pattern, it resets the counter to zero. It might be reducable to something like

:g/.../if getline(line('.')-1) =~ @/

which might be a little easier to read/understand, as it uses the search register.

Just a few ideas.

Thanks.  vim rocks!

f4<CR>

What a beautiful world is this we live on!

thanks,

josé

Reply via email to