-
-
Save dkasak/6ae1c6bf0d771155f23b to your computer and use it in GitHub Desktop.
vim XDG Base Directory support
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
" XDG Environment For VIM | |
" ======================= | |
" | |
" References | |
" ---------- | |
" | |
" - http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables | |
" - http://tlvince.com/vim-respect-xdg | |
" - https://gist.github.com/kaleb/3885679 (the original version) | |
" | |
" Instructions | |
" ------------ | |
" | |
" 1. Create the following directory structure: | |
" | |
" - $XDG_CACHE_HOME/vim | |
" - $XDG_CACHE_HOME/vim/undo | |
" - $XDG_CACHE_HOME/vim/swap | |
" - $XDG_CACHE_HOME/vim/backup | |
" - $XDG_CONFIG_HOME/vim | |
" - $XDG_DATA_HOME/vim/bundle (optional, for a plugin manager such as Vundle) | |
" | |
" Example commands: | |
" `mkdir -p $XDG_CACHE_HOME/vim/{undo,swap,backup} $XDG_CONFIG_HOME/vim` or | |
" `mkdir -p $HOME/.cache/vim/{undo,swap,backup} " $HOME/.config`. | |
" | |
" 2. Source this file near the top of your vimrc (but *below* set nocompatible, | |
" since setting that resets the viminfo setting) | |
" 3. (Optional) vim still tries to read your vimrc from standard paths, so if | |
" you want to move it elsewhere (e.g. $XDG_CONFIG_HOME/vim/vimrc), you can | |
" do oneof of two things: | |
" 3a. Always run vim using "vim -u <path_to_vimrc>". | |
" 3b. Set the environment variable VIMINIT to "source <path_to_vimrc>" | |
" (the content of VIMINIT can be any ex command). | |
if empty("$XDG_CACHE_HOME") | |
let $XDG_CACHE_HOME="$HOME/.cache" | |
endif | |
if empty("$XDG_CONFIG_HOME") | |
let $XDG_CONFIG_HOME="$HOME/.config" | |
endif | |
if empty("$XDG_DATA_HOME") | |
let $XDG_DATA_HOME="$HOME/.local/share" | |
endif | |
set directory=$XDG_CACHE_HOME/vim/swap,~/,/tmp | |
set backupdir=$XDG_CACHE_HOME/vim/backup,~/,/tmp | |
set undodir=$XDG_CACHE_HOME/vim/undo,~/,/tmp | |
set viminfo+=n$XDG_CACHE_HOME/vim/viminfo | |
set runtimepath+=$XDG_CONFIG_HOME/vim,$XDG_CONFIG_HOME/vim/after,$VIM,$VIMRUNTIME | |
let $MYVIMRC="$XDG_CONFIG_HOME/vim/vimrc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@aod Hey, thanks. The reason I used
XDG_CACHE_HOME
is that I consider undo info and backups as non-essential. The logic I use is this: in a regular situation, would I lose data (code, documents, etc) by deleting this content? The answer is no, unless it's an outlier situation where I already lost the original data. On the other hand, if a program needs a place to store its primary database, that's a clear case forXDG_DATA_HOME
since that's the primary copy of the data. I'll take your suggestion into account and think about it, though.