Last week I mentioned that in the course of switching from Notepad++ to Vim I lost the ability to run Stata do-files or selected lines from within the text editor, and I asked my readers for help if they had a solution. What do you know, one of them did, and wrote to me all the way from China with a Vim script that solves both problems. I won't repeat it here because it is almost identical to this one. Clearly, I need to remember to always look into the Statalist archive first.
There was one line that I had to change, where Vim is ordered to clean up after itself. Every time you runDoLines() you produce a bunch of .tmp.do files in your %temp% directory, which Vim knows as $TEMP. Though this
au VimLeave * exe "!del -y " temp
should have deleted them, on my computer it did not. This one did:
au VimLeave * silent exe '!del /Q "'.$TEMP.'\*.tmp.do"'
Another thing I tinkered with was the way Vim handles these backup files that end in a tilde. You can disable them entirely, by adding
set nobackup nowritebackup
to _vimrc as explained here. You can also have Vim keep them somewhere you can delete them explicitly, in bulk, as explained here. Finally, you can use a combination of both: you save backup files while Vim is working, but then you make it delete them all when it starts next time. That is explained here. I went with it, so after I created a temp folder in $VIMRUNTIME, I added this to my _vimrc file:
" Keeps backups in $VIMRUNTIME\temp folder, cleans them up
silent execute '!mkdir "'.$VIMRUNTIME.'\temp"'
silent execute '!del /Q "'.$VIMRUNTIME.'\temp\*~"'
In the process of figuring this out, I also discovered that there's a quick way to clean up %temp% thoroughly, as shown here. Good to know. One of these days I might add that to _vimrc too. Now I'm on a roll.