There comes a time where I'm in a situation of downloading multiple files. And the name of files are in series. Something like.


and so on.

Suppose there are files from img01.jpg to img49.jpg. What is the best way to write the full URL of the image on each line (as done above) without repetition? So that I can pass wget the list with -i parameter?

P.S.: Don't tell me I can do curl http://www.example.com/files/images/img{01,49}.jpg in bash to accomplish my work.

  • 8
    You can do curl http://www.example.com/files/images/img{01,49}.jpg in bash to accomplish your work.
    – romainl
    Nov 25, 2015 at 6:13
  • @romainl You forced me to sign up to reply to your comment. Now let me tell you that I'm using Windows. and { & } are bash expansion. So no luck on Powershell, at least. Nov 25, 2015 at 6:33
  • Well, you will need to log in to accept my answer anyway so…
    – romainl
    Nov 25, 2015 at 10:18
  • I got a problem with my accounts: meta.stackexchange.com/q/269958/181377 Nov 25, 2015 at 18:38

4 Answers 4


Here is a different version, that assumes you have Vim 7.4.754 (25 Jun 2015) or newer:

If you have this line:


Now copy and paste it 48 times yy48p. Then go to the second line, visually block select the 01 down to the bottom and press g<C-A>

You might need to adjust your 'nrformat' settings as romainl said in his answer.

  1. Assuming you have this line:

  2. Start recording in some alphabetic register, say q:

  3. Yank the line:

  4. Put it below the current line:

  5. Increment the number:

  6. Stop the recording:

  7. Play it back 47 times:


In short:


Note that you will almost certainly need to tell Vim to stop considering numbers starting with 0 as octal numbers:

:set nrformats-=octal
  • Your answer was cool too, but I chose Christian's because it involves fewer keystrokes. :) Nov 26, 2015 at 19:18

Another option is to use :substitute command together with sub-replace-\=, and using the line numbers to get the increments.

You can start with the line


and duplicate it enough times with the yy48p. After that, the substitute command would be

:%s/01/\=printf('%02d', line('.'))

A more general form to perform the same action is

%s/img\zs\d\{2}/\=printf('%02d', line('.'))

Where you use \zsto anchor the number reference to certain location in the pattern (if there were multiple numbers) and don't need to necessarily have the same number on each line when you start the substitution. You can also include an offset if needed:

%s/img\zs\d\{2}/\=printf('%02d', line('.')+4)
  • It's too much for this trivial problem. :P By the way thanks for the answer. Nov 27, 2015 at 11:41

Like Cajanus, start with one line:


and duplicate it 48 times:


Using visincr.vim, use ctrl-v to visual-block select the 01s. Then

:II 1 0

You can get visincr.vim from


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.