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.

  • 7
    You can do curl http://www.example.com/files/images/img{01,49}.jpg in bash to accomplish your work. – romainl Nov 25 '15 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. – Santosh Kumar Nov 25 '15 at 6:33
  • Well, you will need to log in to accept my answer anyway so… – romainl Nov 25 '15 at 10:18
  • I got a problem with my accounts: meta.stackexchange.com/q/269958/181377 – Santosh Kumar Nov 25 '15 at 18:38

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.

| improve this 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
| improve this answer | |
  • Your answer was cool too, but I chose Christian's because it involves fewer keystrokes. :) – Santosh Kumar Nov 26 '15 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)
| improve this answer | |
  • It's too much for this trivial problem. :P By the way thanks for the answer. – Santosh Kumar Nov 27 '15 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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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