Skip to content

Instantly share code, notes, and snippets.

Last active Jul 2, 2021
What would you like to do?
VIM XDG Configuration
" XDG Environment For VIM
" =======================
" References
" ----------
" -
" -
if empty($XDG_CACHE_HOME)
let $XDG_CACHE_HOME = '~/.cache'
if empty($XDG_CONFIG_HOME)
let $XDG_CONFIG_HOME = '~/.config'
if !isdirectory($XDG_CACHE_HOME . "/vim/swap")
call mkdir($XDG_CACHE_HOME . "/vim/swap", "p")
set directory=$XDG_CACHE_HOME/vim/swap//,/var/tmp//,/tmp//
if !isdirectory($XDG_CACHE_HOME . "/vim/backup")
call mkdir($XDG_CACHE_HOME . "/vim/backup", "p")
set backupdir=$XDG_CACHE_HOME/vim/backup//,/var/tmp//,/tmp//
" Double slash does not actually work for backupdir, here's a fix
au BufWritePre * let &backupext='@'.substitute(substitute(substitute(expand('%:p:h'), '/', '%', 'g'), '\', '%', 'g'), ':', '', 'g')
" see :help persistent-undo
if !isdirectory($XDG_CACHE_HOME . "/vim/undo")
call mkdir($XDG_CACHE_HOME . "/vim/undo", "p")
set undodir=$XDG_CACHE_HOME/vim/undo//,/var/tmp//,/tmp//
set undofile
set viminfo+=n$XDG_CACHE_HOME/vim/viminfo
set runtimepath-=~/.vim
set runtimepath^=$XDG_CONFIG_HOME/vim
set runtimepath-=~/.vim/after
set runtimepath+=$XDG_CONFIG_HOME/vim/after
source $XDG_CONFIG_HOME/vim/vimrc

This comment has been minimized.

Copy link

@dkasak dkasak commented Feb 26, 2015

This should be added:

set undodir=$XDG_CACHE_HOME/vim,~/,/tmp

Also consider separating these paths into separate directories under the $XDG_CACHE_HOME/vim directory so the files are easier to find in case a manual manipulation is needed, like this:

set directory=$XDG_CACHE_HOME/vim/swap,~/,/tmp
set backupdir=$XDG_CACHE_HOME/vim/backup,~/,/tmp
set undodir=$XDG_CACHE_HOME/vim/undo,~/,/tmp

This comment has been minimized.

Copy link
Owner Author

@kaleb kaleb commented May 8, 2015

@dkasak I actually did end up doing something similar. I should update this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment