I think, the easiest solution would facilitate a macro. Assuming you
have written dummy01 and the cursor is on the word dummy, record the
macro into register a like this:
qayyp$^Aq
(where ^A ist a literal Ctrl-A key press not the 2 keys ^ and A).
And then execute 100@a which executes the macro stored in register a.
Note, that you can also fill the register explicitly, if you know
exactly what to execute (^A ist inserted as Ctrl-V Ctrl-A):
:let @a="yyp$^A"
100@a
Another solution, which would only work with vim 7.2 with patch 295
included uses a little bit scripting:
:let list=repeat(["dummy"], 100)
:call map(list, 'v:val.printf("%02d",v:key+1)')
:call append("$", list)
regards,
Christian
For the whole file, you can do this:
:%s/$/\=printf('%04d', line('.'))
or, for a sub-range of the file
:'<,'>s/$/\=printf('%04d', 1+line('.') - line("'<"))
Adjust the format string for the required padding.
-tim
Tim suggested:
:%s/$/\=printf('%04d', line('.'))
:'<,'>s/$/\=printf('%04d', 1+line('.') - line("'<"))
If your targets are not one to a line in sequence, try
:let n = 1
:g/whatever/s//\=n/|let n+=1
This idiom is very flexible and easy to remember its bare bones.
Something more like Tim's answer would be
:let n = 1
:g/dummy/s//\=submatch(0).printf('%04d',n)/|let n +=1
for "dummy" anywhere in text, though it gets tricky with more than one
"dummy" on a line.
Regards, John
Have a look at the visincr plugin:
http://www.vim.org/scripts/script.php?script_id=670
--
.
This does the trick in one line, and should work as far back as 7.2.000:
:call append('$', map(range(100), 'printf("dummy%02d", v:val)'))
~Matt
On Mo, 04 Jan 2010, Matt Wozniski wrote:
> This does the trick in one line, and should work as far back as
> 7.2.000:
>
> :call append('$', map(range(100), 'printf("dummy%02d", v:val)'))
True and so easy!
regards,
Christian
--
:wq