从的bash shell脚本中打开VIM [英] open vim from within bash shell script
问题描述
我想bash shell中,做以下
I want bash shell that does the following
- 使用vim打开一个文件
- 写点东西到文件
-
保存并退出该文件
- open a file using vim
- write something into file
save and exit the file
bashpromt# cat mybash.sh
echo "about to open a file"
vim file.txt #I need to use vim application to open a file
#now write something into file.txt
#close the that file.
echo "done."
这可能吗?我发现了一些像vim的脚本,但不知道如何使用它。
或类似的东西这里的doc可以用于此?
IS that possible? I found something like vim script , but not sure how to use it. Or something like "HERE" doc can be used for this ?
编辑:我需要验证vim编辑器是在我们的文件做工精细system.So我需要编写脚本调用vim和做一些命令并关闭它。我的要求并不适合做东西像回声东西> file.txt的。我使用vim打开文件。
I need to verify that vim editor is working fine over our file system.So I need to write script that invokes vim and does some command and close it. My requirement doesn't fit into doing stuffs like "echo "something" > file.txt" . I got to open the file using vim.
推荐答案
Vim有几个选项:
-
-c
=>通过ex命令。例如:VIM myfile.txt的-cWQ
来强制文件的最后一行是换行终止(除非二进制
以某种方式由脚本设置) -
-s
=>播放录制在-W
A scriptout。例如,如果你的文件包含ZZ
,那么VIM myfile.txt的-s the_file_containing_ZZ
会做同样的为previously。
-c
=> pass ex commands. Example:vim myfile.txt -c 'wq'
to force the last line of a file to be newline terminated (unlessbinary
is set in some way by a script)-s
=> play a scriptout that was recorded with-W
. For example, if your file containsZZ
, thenvim myfile.txt -s the_file_containing_ZZ
will do the same as previously.
另外要注意的是,援引为前
,vim会在Ex模式启动;你可以尝试前my_file.txt适用<<< WQ
Also note that, invoked as ex
, vim will start in ex mode ; you can try ex my_file.txt <<< wq
这篇关于从的bash shell脚本中打开VIM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!