简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM