Sunday, December 23, 2012

Re: increment existing numbers by 1

On Sun, Dec 23, 2012 at 8:33 PM, stosss <stosss@gmail.com> wrote:
> I found this. I think it is what I want but I don't understand what it
> is doing or how to initiate it.
>
> http://vim.wikia.com/wiki/Substitute_with_incrementing_numbers
>
> Incrementing selected numbers
>
> function! Incr()
> let a = line('.') - line("'<")
> let c = virtcol("'<")
> if a > 0
> execute 'normal! '.c.'|'.a."\<C-a>"
> endif
> normal `<
> endfunction
> vnoremap <C-a> :call Incr()<CR>
>
>
> I want to increment numbers that exist by 1. I also don't want it to
> change other numbers only numbers in a certain pattern. The pattern
> that I want to manipulate is:
>
> :'y,'zs@^[ ]*<navPoint id="navPoint-\zs\(\d\d\d\)\ze">$@not sure what
> I would put here@
>
> I have tried several different attempts with s@pattern@replace@ but
> each one would skip every other pattern.
>
> So if the number was 242 I want it to change to 243 and then that one
> change to 244 etc. That would happen on only the pattern in the range
> 'y,'z or the actual line numbers could be the range. The pattern
> number of each line needs to become the pattern number of the next
> pattern after it. The spacing between the lines with the pattern
> varies from five lines to six lines.
>
> The number in the pattern is the only number on the line.
>
> I have several hundred lines scattered over about 3000 lines that need
> to be edited but the only way I know how to do it is manually one line
> at a time. I am obviously trying to avoid that pain.
>
> Can anyone point me to a solution or tell me if I found the solution
> and how to use it?
>
> Thanks for any help

I found my answer now I have some more tools in my Vim bag.

'y,'zs@navPoint-\zs\d\d\d\ze@\=submatch(0) + 1@

It worked great!

--
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

No comments: