Executing Vim commands in a shell script

前端 未结 3 1986
北荒
北荒 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:34

    I think vim -w/W and vim -s is what you are looking for.

    The "Vim operations/key sequence" you could also record with vim -w test.keys input.file. You could write the test.keys too. For example, save this in the file:

    ggwxjddZZ
    

    This will do:

    Move to the first line,
    move to the next word,
    delete one character,
    move to the next line,
    delete the line, and
    save and quit.
    

    With this test.keys file, you could do:

    vim -s test.keys myInput.file
    

    Your "myInput.file" would be processed by the above operations, and saved. You could have that line in your shell script.

    VimGolf is using the same way to save the user's solution.

提交回复
热议问题