How to run a series of vim commands from command prompt

后端 未结 5 1446
野的像风
野的像风 2021-01-30 16:17

I have four text files A.txt, B.txt, C.txt and D.txt I have to perform a series of vim editing in all these files. Currently how I am doing is open each files and do the same vi

5条回答
  •  礼貌的吻别
    2021-01-30 17:14

    With all the commands you want to run on each file saved in a script, say "script.vim", you can execute that script on one file like this (as others have mentioned):

    vim -c "source script.vim" A.txt
    

    Taking this one step further, you can save your file at the end of the script, either by putting a :w command inside the script itself, or passing it from the command-line:

    vim -c "source script.vim | w" A.txt
    

    Now, you can run any command in Vim on multiple files, by using the argdo command. So your command turns into:

    vim -c "argdo source script.vim | w" A.txt B.txt C.txt D.txt
    

    Finally, if you want to quit Vim after running your script on every file, just add another command to quit:

    vim -c "argdo source script.vim | w" -c "qa" A.txt B.txt C.txt D.txt
    

提交回复
热议问题