I use the following (from my lh-vim-lib library plugin):
function! lh#path#vimfiles() abort
let re_HOME = lh#path#to_regex($HOME.'/')
let re_LUCHOME = exists('$LUCHOME') ? '\|'.lh#path#to_regex($LUCHOME.'/'): ''
let what = '\%('.re_HOME.re_LUCHOME.'\)'.'\(vimfiles\|.vim\|.config[/\\]nvim\)'
" Comment what
let z = lh#path#find(&rtp,what)
return z
endfunction
function! lh#path#to_regex(path) abort
let regex = substitute(a:path, '[/\\]', '[/\\\\]', 'g')
return regex
endfunction
function! lh#path#find(paths, regex) abort
let paths = (type(a:paths) == type([]))
\ ? (a:paths)
\ : split(a:paths,',')
call filter(paths, 'match(v:val, a:regex) != -1')
let shortest = lh#list#arg_min(paths, function('len'))
return empty(paths) ? '' : paths[shortest]
endfunction
function! lh#list#arg_min(list, ...) abort
if empty(a:list) | return -1 | endif
if a:0 > 0
let Transfo = a:1
let list = map(copy(a:list), '[Transfo(v:val), v:key]')
else
let list = map(copy(a:list), '[v:val, v:key]')
endif
let res = [list[0]]
call map(list[1:], 'add(res, v:val[0] < res[-1][0] ? v:val : res[-1])')
return res[-1][1]
endfunction
It's somehow overkill, but at least it permits me to share accounts (in that case I put my configuration stuff in ~/luc
and I set $LUCHOME
-- yeah this is really bad, but sometimes very bad practices are enforced), and it works with vim (windows and *nix), and neovim apparently, and it supports any value for shellslash. It doesn't expect ~/{.vim,vimfiles}/
to be the first directory in &rtp
either.
.vim
works on Windows as well as on Linux, however it might be hard to actually create that folder, but I have used that as my main configuration folder for at least 10 years.vim
on windows? I have just renamedvimfiles
to.vim
and my config is not applied both on gVim and vim in cmd.call plug#begin()
with no arguments and it will default to aplugged
directory under the appropriate subdirectory of your home directory.