-
-
Save joshuata/600b2969f9ce35ec3323c4d996e8542c 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_STATE_HOME/vim | |
" - $XDG_STATE_HOME/vim/undo | |
" - $XDG_STATE_HOME/vim/swap | |
" - $XDG_STATE_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_STATE_HOME/vim/{undo,swap,backup} $XDG_CONFIG_HOME/vim` or | |
" `mkdir -p $HOME/.local/state/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_CONFIG_HOME) | |
let $XDG_CONFIG_HOME=$HOME."/.config" | |
endif | |
if empty($XDG_DATA_HOME) | |
let $XDG_DATA_HOME=$HOME."/.local/share" | |
endif | |
if empty($XDG_STATE_HOME) | |
let $XDG_STATE_HOME=$HOME."/.local/state" | |
endif | |
set directory=$XDG_STATE_HOME/vim/swap,~/,/tmp | |
set backupdir=$XDG_STATE_HOME/vim/backup,~/,/tmp | |
set undodir=$XDG_STATE_HOME/vim/undo,~/,/tmp | |
set viminfo+=n$XDG_STATE_HOME/vim/viminfo | |
set runtimepath+=$XDG_CONFIG_HOME/vim,$XDG_CONFIG_HOME/vim/after,$VIM,$VIMRUNTIME | |
let $MYVIMRC=$XDG_CONFIG_HOME."/vim/init.vim" | |
source $MYVIMRC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment