How to run a series of vim commands from command prompt

后端 未结 5 1447
野的像风
野的像风 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:00

    vim -c  Execute  after loading the first file
    

    Does what you describe, but you'll have to do it one file at a time.

    So, in a windows shell...

    for %a in (A,B,C,D) do vim -c ":g/^\s*$/d" -c "" %a.txt
    

    POSIX shells are similar, but I don't have a machine in front of me at the moment.

    I imagine you could load all the files at once and do it, but it would require repeating the commands on the vim command line for each file, similar to

    vim -c "" -c "" -c ":n" (repeat the previous -c commands for each file.)  
    

    EDIT: June 08 2014: Just an FYI, I discovered this a few minutes ago.

    vim has the command bufdo to do things to each buffer (file) loaded in the editor. Look at the docs for the bufdo command. In vim, :help bufdo

提交回复
热议问题