vimrc.d/paths.vim
ΒΆ
Enforce vim script implementation to reduce ambiguities and improve robustness:
scriptversion 4
Find XDG base directory specification compliant locations for data files:
for [s:type, s:path] in [
\ ['cache', '~/.cache'],
\ ['config', '~/.config'],
\ ['data', '~/.local/share'],
\ ]
let s:envvar = printf('$XDG_%s_HOME', toupper(s:type))
const g:xdg_{s:type}_dir = expand(exists(s:envvar) ? s:envvar : s:path)
endfor
vim specific paths honouring XDG base directory specification:
for s:name in ['cache', 'config', 'data']
const g:vim_{s:name}_dir = g:xdg_{s:name}_dir .. '/vim'
if !isdirectory(g:vim_{s:name}_dir)
call mkdir(g:vim_{s:name}_dir, 'p')
endif
endfor