Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.


hpr3070 :: making vim xdg compatible

move your vim configuration out of the home directory

<< First, < Previous, Latest >>

Hosted by crvs on 2020-05-08 is flagged as Explicit and is released under a CC-BY-SA license.
Tags: vim, configuration, XDG.
Listen in ogg, spx, or mp3 format. | Comments (0)

Part of the series: Vim Hints

Various contributors lead us on a journey of discovery of the Vim (and vi) editors.

Vim is a highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor distributed with most UNIX systems.

http://www.vim.org/about.php

xdg vim config

To make vim load an alternative config file either use an alias or the VIMINIT variable. i.e. place either alias vim="vim -u ~/.config/vim/vimrc" or VIMINIT="source ~/.config/vim/vimrc" in your .bashrc (ironically, that one is still in my home folder).

Once that is loaded, you should source the following file after "nocompatible"

" file: ~/.config/vim/xdg.vim
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,$XDG_DATA_HOME/vim/bundle/Vundle.vim,$VIM,$VIMRUNTIME
let $MYVIMRC=$XDG_CONFIG_HOME."/vim/vimrc"

With this file in place you should call it from your vimrc

" file: ~/.config/vim/vimrc
set nocompatible
filetype off
source $HOME/.config/vim/xdg.vim
call vundle#begin()
let vundle#bundle_dir = expand("$XDG_DATA_HOME/vim/bundle")

" include your calls to Plugin here

call vundle#end()
filetype plugin indent on
syntax on

source ~/.config.

Note that it is important that all the paths are defined BEFORE Vundle (or whatever is your plugin manager) is called, since the path to it is defined in xdg.vim.

You can check my full vim config at gitlab.

References

The vim script I modified my config from - https://gist.github.com/dkasak/6ae1c6bf0d771155f23b


Comments

Subscribe to the comments RSS feed.

<< First, < Previous, Latest >>

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the P in HPR stand for ?
Are you a spammer →
Who hosted this show →
What does HPR mean to you ?