Support the XDG_STATE_HOME directory

It's a better place to store most of the stuff Vim wants to store lying
around on the filesystem than XDG_CACHE_HOME, it turns out? I'm still
keeping installed packages primarily in XDG_CACHE_HOME, since if that
directory is blown away then the same packages just get reinstalled
automatically and nothing particularly important is lost, but the other
stuff doesn't really belong in there.

Undo files, viminfo, and so on are definitely a good example of "state
data that should be persisted between (application) restarts, but that
is not important or portable enough to the user that it should be stored
in XDG_DATA_HOME", so XDG_STATE_HOME is a fine place for them.
This commit is contained in:
Danielle McLean 2021-09-22 10:35:51 +10:00
parent 08990a8df5
commit ad496a7745
Signed by: 00dani
GPG key ID: 9DDE1EDE01E3A605
2 changed files with 6 additions and 6 deletions

View file

@ -71,14 +71,14 @@ else
endif endif
for s:dir in ['backup', 'swap', 'undo'] for s:dir in ['backup', 'swap', 'undo']
call s:ensure_dir($XDG_CACHE_HOME . '/vim/' . s:dir) call s:ensure_dir($XDG_STATE_HOME . '/vim/' . s:dir)
endfor endfor
set backupdir=.,$XDG_CACHE_HOME/vim/backup set backupdir=.,$XDG_STATE_HOME/vim/backup
set directory=.,$XDG_CACHE_HOME/vim/swap set directory=.,$XDG_STATE_HOME/vim/swap
if exists('+undofile') if exists('+undofile')
set undofile set undofile
set undodir=$XDG_CACHE_HOME/vim/undo set undodir=$XDG_STATE_HOME/vim/undo
endif endif
let g:airline_powerline_fonts = 1 let g:airline_powerline_fonts = 1

4
vimrc
View file

@ -1,11 +1,11 @@
for [s:var, s:value] in items({'XDG_CONFIG_HOME': '~/.config', 'XDG_CACHE_HOME': '~/.cache', 'XDG_DATA_HOME': '~/.local/share'}) for [s:var, s:value] in items({'XDG_CONFIG_HOME': '~/.config', 'XDG_CACHE_HOME': '~/.cache', 'XDG_DATA_HOME': '~/.local/share', 'XDG_STATE_HOME': '~/.local/state'})
if (empty(eval('$' . s:var))) if (empty(eval('$' . s:var)))
exec 'let $' . s:var . ' = expand(s:value)' exec 'let $' . s:var . ' = expand(s:value)'
endif endif
endfor endfor
set runtimepath=$XDG_CONFIG_HOME/vim,$XDG_CACHE_HOME/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$XDG_CONFIG_HOME/vim/after,$XDG_CACHE_HOME/vim/after set runtimepath=$XDG_CONFIG_HOME/vim,$XDG_CACHE_HOME/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$XDG_CONFIG_HOME/vim/after,$XDG_CACHE_HOME/vim/after
set viminfo+=n$XDG_CACHE_HOME/vim/viminfo set viminfo+=n$XDG_STATE_HOME/vim/viminfo
if exists('+packpath') if exists('+packpath')
set packpath^=$XDG_CONFIG_HOME/vim,$XDG_CACHE_HOME/vim set packpath^=$XDG_CONFIG_HOME/vim,$XDG_CACHE_HOME/vim
endif endif