我正在编写一个运行命令行程序 (Gromacs) 的 Bash 脚本,保存结果,修改输入文件,然后再次循环整个过程。
我正在尝试使用 Vim 修改输入文本文件,但我一直无法找到一种方法来在打开后从 .sh 文件中执行内部 Vim 命令,如 :1234、w、x、dd 等我在 Vim 中的输入文件(“vim conf.gro”)。
有没有一种实用的方法可以从 shell 脚本执行 Vim 命令?
最佳答案
我认为vim -w/W and vim -s
正是您要找的。p>
你也可以用 vim -w test.keys input.file
记录“Vim 操作/键序列” .你可以写 test.keys
也。例如,将其保存在文件中:
ggwxjddZZ
这样做会:
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.
有了这个test.keys
文件,你可以这样做:
vim -s test.keys myInput.file
您的“myInput.file”将由上述操作处理并保存。您可以在 shell 脚本中包含该行。
VimGolf正在使用相同的方式来保存用户的解决方案。
关于macos - 在 shell 脚本中执行 Vim 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18860020/