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
:%s/V1/V2/g
Is there a easiler way to do this?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityI'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
:%s/V1/V2/g
Is there a easiler way to do this?
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
.
: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
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