Search code examples
bashvimcross-platformdotfiles

Decide Vimfiles directory from Bash


I would like to get the vimfiles directory of the user. Given that users can presumable use directories other than ~/.vim/, retrieving the directory from vim's vimfiles variable would be the optimal cross-platform way to do it. But how?

I think calling something like vim -q -c COMMAND might actually be the solution, but am not sure about the COMMAND to be used.


Solution

  • I think this will do what you want.

    vim -c ':exec ":silent !echo ".&rtp | exec ":q!"'
    

    On my laptop this is the result (reformatted for readability).

    /Users/dan/.vim,/Users/dan/.vim/bundle/ack,/Users/dan/.vim/bundle/fugitive,
    /Users/dan/.vim/bundle/json,/Users/dan/.vim/bundle/my-ackmore,
    /Users/dan/.vim/bundle/my-endwise,/Users/dan/.vim/bundle/pathogen,
    /Users/dan/.vim/bundle/perl,/Users/dan/.vim/bundle/pgsql,
    /Users/dan/.vim/bundle/quickrun,/Users/dan/.vim/bundle/repeat,
    /Users/dan/.vim/bundle/signify,/Users/dan/.vim/bundle/statline,
    /Users/dan/.vim/bundle/surround,/Users/dan/.vim/bundle/tcomment,
    /usr/share/vim/vimfiles,/usr/share/vim/vim73,
    /usr/share/vim/vimfiles/after,/Users/dan/.vim/after
    

    You can read more about Vim startup in :help $VIM.

    UPDATE: as requested, here is a variation to only show the first entry in the list, which I think should be vimfiles:

    vim -c ':exec ":silent !echo " . split(&rtp,",")[0] | exec ":q!"'