0

I have a directory ~/.vim/rc.d/ that houses various configuration files. I like this pattern for configuring various things in my homedir because it modularizes configuration options.

The problem is that my vimrc is now a series of commands to source hard-coded paths to other .vim files.

source ~/.vim/rc.d/00-plugins.vim
source ~/.vim/rc.d/01-plugins-settings.vim
source ~/.vim/rc.d/02-interface-colorscheme.vim
source ~/.vim/rc.d/02-interface-listchars.vim

Etc.

How can I rewrite this to source all the files in that directory that end in .vim?

2
  • 2
    See :h glob(), :h :for – Matt Aug 13 '20 at 9:09
  • Welcome to Vi and Vim! You may be interested in :help startup – D. Ben Knoble Aug 13 '20 at 13:56
4

You can put all your files to ~/.vim/plugin/ directory and they would be sourced by vim automatically.

Basically vim does :runtime all vim files from that directory.

If you still want to do it by hand you can :runtime! ~/.vim/rc.d/**/*.vim

You can also use glob() function to get all your vim filenames and source them in a for loop.

2
  • Thanks, since I had nothing in ~/.vim/plugin I removed it and created a symlink to ~/.vim/rc.d and that seems to be working. – causaSui Aug 13 '20 at 11:30
  • Actually, this symlinking seems to have broken vim-plug. I did not have success adding the runtime! command to my vimrc either unfortunately :( – causaSui Sep 1 '20 at 19:30
3

The doc :h :runtime says:

:ru[ntime][!] [where] {file} ..
            Read Ex commands from {file} in each directory given
            by 'runtimepath' and/or 'packpath'.  There is no error
            for non-existing files.
            [...]
            When [!] is included, all found files are sourced.
            [...]
            When {file} contains wildcards it is expanded to all
            matching files.  Example: >
                :runtime! plugin/*.vim

So you should be able to use runtime! ~/.vim/rc.d/*

1
  • Unfortunately this seems to break vim-plug. I'm not sure why – causaSui Sep 1 '20 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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