Executing Vim commands in a shell script

前端 未结 3 1970
北荒
北荒 2021-02-02 13:43

I am writing a Bash script that runs a command-line program (Gromacs), saves the results, modifies the input files, and then loops through the process again.

I am trying

3条回答
  •  不知归路
    2021-02-02 14:43

    You can script Vim via the -c flag.

    vim  -c "set ff=dos" -c wq mine.mak
    

    However that only gets you so far.

    • From the commands you gave it looks like you are trying to run some normal commands. You will need to use :normal. e.g. :norm dd
    • Writing all this on the command line is asking for trouble. I suggest you make a Vim file (e.g. commands.vim) and then :source via -S.
    • You probably want to get good and conformable Vim's ex commands. Take a look at :h ex-cmd-index

    So you will end up with something like this. With all your Vim commands inside of commands.vim.

    vim -S commands.vim mine.mak
    

    You may also want to look into using sed and/or awk for text processing.

提交回复
热议问题