Open Vim from within a Bash shell script

后端 未结 5 1763
臣服心动
臣服心动 2021-02-01 07:24

I want to write a Bash shell script that does the following:

  1. Opens a file using Vim;
  2. Writes something into the file;
  3. Saves the file and exits.
5条回答
  •  旧时难觅i
    2021-02-01 08:16

    Vim has several options:

    • -c => pass ex commands. Example: vim myfile.txt -c 'wq' to force the last line of a file to be newline terminated (unless binary is set in some way by a script)
    • -s => play a scriptout that was recorded with -W. For example, if your file contains ZZ, then vim myfile.txt -s the_file_containing_ZZ will do the same as previously.

    Also note that, invoked as ex, vim will start in ex mode ; you can try ex my_file.txt <<< wq

提交回复
热议问题