I'm recently working on a project in vim, and I need to execute the same command in command-line mode multiple times to different files which are in the same folder. like


Is there a easiler way to do this?

2 Answers 2


Fill up the args list (:args …; note there are some nice shorthands so you don’t need to list out every file often) then use :argdo <cmd>. There is also :bufdo, :cdo, and more. This last is particularly handy with :grep/:vimgrep.

  • 1
    I'm a (old) vi guy using vim by inheritance. Can you provide the exact syntax to do what Daybreak asked? I'm not familiar with what an args list is, or how to use argdo.
    – Sinc
    May 27 at 13:31
  • 2
    See the :help :args entry and references @Sinc the syntax to populate args depends on the fast way to find files (search? Match a glob?) but the syntax to actually run the command is simply :argdo %substitute/V1/V2/ge
    – D. Ben Knoble
    May 27 at 14:16
  • That beats copying the substitute string and then doing a whole lot of {paste :wn} pairs! I love lazy programmers who like to make repetition easy!
    – Sinc
    May 27 at 19:16

Perhaps call out to sed:

:!sed -i 's/V1/V2/g' %:p:h/*

The last parameter is documented in

  • :he cmdline-special
  • :he filename-modifiers

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.