Tim Chase wrote:

> leandromartinez98 wrote:
> > Just for the sake of records, the very nice commands suggested here
> > don't work well if the numbers have leading zeroes. For example,
> > using

Did you try removing "octal" from 'nrformats'?

> >  :'<,'>s/\%V\d\+/\=submatch(0)+5
> > 
> > in a table like:
> > 
> > 0101
> > 0102
> > 0103
> > 0104
> > 
> > provides
> > 
> > 70
> > 71
> > 72
> > 73
> > 74
> 
> You can tweak your regexp to strip the leading zeros:
> 
>    :\<,\>s/\%V\(0*\)\d\+/\=submatch(2)+5
> 
> However, it will eat the leading zeros, not replacing them after 
> the substitution.  If you know the width, you can hack it even 
> further with
> 
>    \=matchstr(repeat('0', 4) . (submatch(2)+5), '.\{4}$')
> 
> where "4" is the number of characters to pad to, and "5" is the 
> increment you want.

Using printf("%04d", n) would be simpler and avoids dropping digits if
the number happens to be bigger than expected.

-- 
The psychic said, "God bless you."  I said, "I didn't sneeze."  She
looked deep into my eyes and said, "You will, eventually."  And, damn
if she wasn't right.  Two days later, I sneezed.  --Ellen Degeneres

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to