1

I'm a Mac user and I was wondering if there was a way to put all of my dotfiles to a .config folder to store all of them (something analogue to XDG Directories on Linux).

I was trying to set up a .vimrc file but as soon as I move it in ~/.config a new one gets created in ~/.

Thank you!

2 Answers 2

3

vim predates the XDG spec, and doesn't follow it. You could override the path to the config file using the VIMINIT variable in your shell profile, according to https://tlvince.com/vim-respect-xdg

I've found it easier to just symlink .vimrc -> .config/vimrc and call it good.

3

Since 7.3.1178 vim will search for ~/.vim/vimrc if ~/.vimrc is not found.

$ cat "$XDG_CONFIG_HOME"/vim/vimrc
set runtimepath^=$XDG_CONFIG_HOME/vim
set runtimepath+=$XDG_DATA_HOME/vim
set runtimepath+=$XDG_CONFIG_HOME/vim/after

set packpath^=$XDG_DATA_HOME/vim,$XDG_CONFIG_HOME/vim
set packpath+=$XDG_CONFIG_HOME/vim/after,$XDG_DATA_HOME/vim/after

let g:netrw_home = $XDG_DATA_HOME."/vim"
call mkdir($XDG_DATA_HOME."/vim/spell", 'p')

set backupdir=$XDG_STATE_HOME/vim/backup | call mkdir(&backupdir, 'p')
set directory=$XDG_STATE_HOME/vim/swap   | call mkdir(&directory, 'p')
set undodir=$XDG_STATE_HOME/vim/undo     | call mkdir(&undodir,   'p')
set viewdir=$XDG_STATE_HOME/vim/view     | call mkdir(&viewdir,   'p')

if !has('nvim') | set viminfofile=$XDG_STATE_HOME/vim/viminfo | endif
$ cat ~/.profile
export GVIMINIT='let $MYGVIMRC="$XDG_CONFIG_HOME/vim/gvimrc" | source $MYGVIMRC'
export VIMINIT='let $MYVIMRC="$XDG_CONFIG_HOME/vim/vimrc" | source $MYVIMRC'

[G]VIMINIT environment variable will also affect Neovim. If separate configs for Vim and Neovim are desired then the following will be a better choice:

export GVIMINIT='let $MYGVIMRC = !has("nvim") ? "$XDG_CONFIG_HOME/vim/gvimrc" : "$XDG_CONFIG_HOME/nvim/init.gvim" | so $MYGVIMRC'
export VIMINIT='let $MYVIMRC = !has("nvim") ? "$XDG_CONFIG_HOME/vim/vimrc" : "$XDG_CONFIG_HOME/nvim/init.vim" | so $MYVIMRC'

links:

for more XDG dir support, see https://wiki.archlinux.org/title/XDG_Base_Directory

4
  • 1
    All the information necessary to answer the question must be here in this post. Links should only be used for attribution and perhaps further research. Please EDIT this question to improve it. Jun 20, 2022 at 3:30
  • 1
    @music2myear fixed. sry for new here. Jun 20, 2022 at 3:41
  • With the quality of that answer now, I think you'll do just fine here. Though I'll still suggest reading the Help section to learn how we're not the regular forum, and why. It'll help you get your bearings and fit in better. Jun 20, 2022 at 3:46
  • @music2myear i'll read help section when free. thanks Jun 20, 2022 at 3:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .