Daybreak Texas
Daybreak Texas

Reputation: 65

Vim: The way to execute same command in command-line mode multiple times

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

:%s/V1/V2/g

Is there a easiler way to do this?

Upvotes: 2

Views: 314

Answers (1)

romainl
romainl

Reputation: 196496

It's command-line mode, not "command mode".

From within Vim

  1. Set your :help argument-list to the desired list of files:

    :arg /path/to/dir/*.xyz
    
  2. Perform your substitution on every file in the argument list and write it if there was a change:

    :argdo %s/V1/V2/g | update
    

See :help :arg, :help :argdo, :help :update.

From your shell

  1. Start Vim with each desired file as argument:

    $ vim /path/to/dir/*.xyz
    
  2. Perform your substitution on every file in the argument list and write it if there was a change:

    :argdo %s/V1/V2/g | update
    

Upvotes: 3

Related Questions