问题
I have a question about Vim. So i have a recipients.cfg config file, and it is being used by a script named check.sh that is sending some stats (send like an sms), and is running every minute via cron.
If i Vim recipients.cfg and leave it open for like 10 minutes, will check.sh still be able to use the recipients.cfg and send the stats?
Thank you!
回答1:
Yes.
Vim only creates hidden .swp files of the file you are editing, for recovery purposes, and also to lock other Vim sessions from writing to the file at the same time.
回答2:
Yes, it is safe, a good way to show you how/why is to open a file in vim, write some text and save it with :w
. Now, change some of the text but don't save it. Open a new terminal and cat
the file, to show the contents. You will see the file's contents are the contents at the time of the save, not the contents currently inside your instance of vim. If you type ls -a
you will find a swapfile .swp
or maybe a swo file etc. This is where your current changes are stored whilst vim is open, and as soon as you write (using :w
) the changes from the swp file actually get put inside the file. So your check.sh will read whatever was last written to the file, not whatever is in vim.
来源:https://stackoverflow.com/questions/51420587/opening-a-config-file-in-a-vim-editor-while-being-used-by-a-script