Reputation: 279
I developed a script that will kill all 'vim' processes working on xxx.log files:
ps -ef|grep vim|grep xxx.log|awk '{print $2}'|xargs kill -9
However, the .swp (swap) files remain for each vim instance killed. How can I also delete the swap file in the same script, or other some short solution without searching for the location of the swap etc?
Upvotes: 6
Views: 4252
Reputation: 116
You can add
set noswapfile
to your vimrc. This will cause swap files to not be created in the first place.
Upvotes: 2
Reputation: 172698
Drop the -9
from kill
; this will send the TERM
(inate) signal to Vim, allowing it to clean up and remove the swap file (at least it did for me on Ubuntu).
By using -9
/ KILL
, you don't give the process a chance to clean up. This should only be used for situations where it's absolutely necessary (e.g. when the process is hung or in an endless loop and doesn't react to external signals any more).
Upvotes: 14
Reputation: 36452
Since the swap file contains the name you deleted, you should be able to find it with a appropriate action, too.
However, killing an interactive editor like vim
sounds very wrong on so many levels. You should really consider not doing that. In which situation is that desirable?
Upvotes: 2