Things for the help! And thanks for telling me where I can find more information about it. Your first example actually works for me because the leading 0s aren't in the beginning.
This helps cut out a step. Cheers, Jack On Wed, Oct 17, 2012 at 10:32 PM, Benjamin R. Haskell <[email protected]> wrote: > On Wed, 17 Oct 2012, stosss wrote: > >> Okay I have something that should be achievable but I can't figure it out. >> I have a lot of files with data for books. Each file is a book and is in >> chapters with lines of text. >> >> sample of existing data: >> >> <h2>1</h2><p> >> 1 line of text.<br> >> 2 another line of text.<br> >> 3 lines of text.<br> >> ... >> 10 More lines of text.<br> >> ... >> 100 Even more lines of text.<br> >> >> [...] >> >> >> What I want is: >> >> <h2 id="b001c001">1</h2><p> >> <span id="b001c001v001">1</span> line of text.<br /> >> <span id="b001c001v002">2</span> another line of text.<br /> >> <span id="b001c001v003">3</span> lines of text.<br /> >> ... >> <span id="b001c001v010">10</span> More lines of text.<br /> >> ... >> <span id="b001c001v100">100</span> Even more lines of text. >> >> [...] >> >> >> I can't figure out how to use %03d to change my numbers from 1 to 001 I >> also would like to figure out how to use setreg() to increase this c001 part >> of the id label so it changes to c002 when it is supposed to so I don't have >> to reset my map at every chapter. I need to figure out the first part before >> I figure out the second part. The examples in the VIM tips aren't helping me >> figure this out. Maybe I am looking in the wrong place. >> >> I tried all sorts of things but nothing worked. I don't remember all the >> things I tried but here are a few attempts I made that didn't work: >> >> :%s@\([0-9]\+\)@%03d\1@ >> :%s@\([0-9]\+\)@\=printf("%03d"\1)@ >> :%s@\([0-9]\+\)@\=printf("%03d\1")@ >> >> I don't understand how to use that number format in my search and replace. >> The examples on the pages linked above don't give me any clues. It has been >> a very long time since I have asked for help with VIM. I usually have been >> able to find answers in the tips. But not this time. > > > > For the %03d part: > > :%s@\(\d\+\)@\=printf("%03d", submatch(1))@g > > See: > :help submatch() > > But, that treats numbers that look like octal incorrectly: > > E.g.: > abc010def -> abc008def > (because 010-base-8 is 8-base-10.) > > So consume the zeros ahead of time: > :%s@0\*\(\d\+\)@\=printf("%03d", submatch(1))@g > > -- > Best, > Ben > > -- > 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 -- "When you see that trading is done, not by consent, but by compulsion - when you see that in order to produce, you need to obtain permission from men who produce nothing - when you see that money is flowing to those who deal, not in goods, but in favors - when you see that men get richer by graft and by pull than by work, and your laws don't protect you against them, but protect them against you - when you see corruption being rewarded and honesty becoming a self-sacrifice - you may know that your society is doomed." Ayn Rand -- 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
