> On Apr 4, 2011, at 5:31 PM, Daniel M. Eldridge wrote:
>> How do I insert the current line number into a text file; how can I do
>> this while padding to six digits?
>
>
> This should do the trick:
>
> :%s/^/\=repeat(0,6-len(line('.'))).line('.').'^I'/
>
> ^I represents a tab. It adds the number of zeros, the line number and the
> tab. It uses :help sub-replace-expression
I suggest to use the printf() function, which makes the whole
statement much more readable:
:%s/^/\=printf("%06d\t", line('.'))
regards,
Christian
--
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:
Post a Comment