I'm trying to automate cleaning up old vim undo files that are for files that have since been deleted.
So far I've created a new vim script at
function cleanupUndos#clean() let undofiles = systemlist('ls /Users/me/.vim/undodir/') for undofile in undofiles let filepath = substitute(undofile, "%", "/", "g") if empty(glob(filepath)) echo "File doesn't exist, deleting undofile for " filepath let deleteresult = delete(undofile) echo deleteresult == 0 ? 'SUCCEEDED' : 'FAILED' endif endfor endfunction
And in my
~/.vimrc I've set the undofile and undodir and added the autocmd for running the cleanup:
set undofile set undodir=/Users/me/.vim/undodir autocmd VimEnter * :call cleanupUndos#clean()
The problem is that when I open vim, it immediately prints
FAILED and none of the files ever get deleted. I can run the
delete(filename) command in a vim session and it works, but it doesn't seem to work when run from the script. I've tried different ways of deleting files with no success.
How can I delete files from within a vimscript?
(I'm running Vim version 7.4.8056 on MacOS Sierra 10.12.6.)