I want to write a Bash shell script that does the following:
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
...
# Then close the file.
...
echo 'Done'
Is that possible? I found something called Vimscript, but not sure how to use it. Or something like a here document can be used for this?
Update: I need to verify that Vim is working fine over our file
system. So I need to write script that invokes Vim, executes some
command, and closes it. My requirements do not fit into doing stuffs
like echo 'something' > file.txt
. I need to open the file using Vim.
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