How do I invoke Vim from command line to run a group of commands on a

group of files? There are several ways to invoke Vim from command line to run a group of commands on a group of files. You can use a set of “-c” command line options to specify a group of commands:

    $ vim -c "" -c "" *.txt

Each of the ex-command specified with the “-c” command line option is executed one by one sequentially. You can also use a single “-c” command line option and the “|” character to separate the ex commands:

    $ vim -c " | " *.txt

In the above command, if an ex command fails, then all the remaining ex commands will not be executed. For example, to replace “ABC” with “DEF” in a file from the command-line, you can use the following command:

    $ vim -c "%s/ABC/DEF/ge | update" myfile.txt

To replace “ABC” with “DEF” in multiple files from the command-line, you can use the following command:

    $ vim -c "argdo %s/ABC/DEF/ge | update" *.txt

You can store the group of commands into a file and use the “-s” command line option to run the commands on a set of files. For example, if the group of commands are stored in the file mycmds.txt, then you can use the following command:

    $ vim -s mycmds.txt *.pl

Comments (1)


Pepsh Pepshinsky

Let’s see you to :help viminfo-file-name (option -i) :set viminfofile=NONE


Speak Your Mind