Last active
March 19, 2021 04:16
-
-
Save mllg/5353184 to your computer and use it in GitHub Desktop.
Utility vim function to clean up vim's undo files (or others).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Tmpwatch(path, days) | |
let l:path = expand(a:path) | |
if isdirectory(l:path) | |
for file in split(globpath(l:path, "*"), "\n") | |
if localtime() > getftime(file) + 86400 * a:days && delete(file) != 0 | |
echo "Tmpwatch(): Error deleting '" . file . "'" | |
endif | |
endfor | |
else | |
echo "Tmpwatch(): Directory '" . l:path . "' not found" | |
endif | |
endfunction | |
" undofile part of your .vimrc | |
if exists("+undofile") | |
if !isdirectory($HOME . '/.vimundo') | |
mkdir($HOME . "/.vimundo") | |
endif | |
set undodir=~/.vimundo// | |
set undofile | |
set undolevels=1000 | |
set undoreload=10000 | |
" remove undo files which have not been modified for 31 days | |
call Tmpwatch(&undodir, 31) | |
endif | |
In order to correctly handle filenames containing newline characters, you should use globpath(l:path, '*', 1, 1)
instead of split(globpath(l:path, "*"), "\n")
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool! I used this.
I think L17 should be
call mkdir
though.