Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

For my .bashrc I have a lot of small snippet files in .config/bash, like 10-prompt.sh and so on. In my actual .bashrc, I just have the following:


for file in "$configdir"/*.sh
        source "$file"

I'd like to do the same for my .vimrc, but I am not that confident in VimL that I could write that.

How would the snippet for .vimrc look like that includes all the snippets in a given subfolder? Ideally, I'd like to make a .vim/rc/ folder where I can put my snippets into.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted


This is @queueoverflow's shorter version:

for rcfile in split(globpath("~/.vim/rc", "*.vim"), '\n') 
    execute('source '.rcfile)



(removed my stupid answer)

The function below seems to work.

function! SourceMyScripts()
  let file_list = split(globpath("~/.vim/rc", "*.vim"), '\n')

  for file in file_list
    execute( 'source '.file )

Add it to your ~/.vimrc like that:

call SourceMyScripts()


share|improve this answer
That does not do anything :-/ –  queueoverflow Jun 18 '12 at 10:01
Yes, that's an horribly stupid answer. –  romainl Jun 18 '12 at 11:51
So? Do you know the correct answer or what I did wrong then? –  queueoverflow Jun 18 '12 at 12:47
No, my answer was very stupid. I'm currently trying my hands at a solution. I'm not a vimscript wizard, though. –  romainl Jun 18 '12 at 12:48
Thank you for trying! Currently, I just made cat ~/.vim/rc/*.vim > ~/.vimrc as a workaround, but if Vim was able to do this automatically, that would be even cooler! –  queueoverflow Jun 18 '12 at 12:51
show 3 more comments

A very easy way to do this is ":runtime rc/*.vim". Of course, this would iterate over each "rc" subdirectory that might exist in each of the directories in 'runtimepath', but I doubt that will be a problem.


:help :runtime
:help 'runtimepath'
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.