Entry Guy
Entry Guy

Reputation: 475

Splitting Vim config into multiple files

Here is a part of my config:

call plug#begin('~/.vim/plugged')

" Here I want to split my Vim config into multiple files
" I'm including other Vim configuration files

for f in glob('.vim/*.vim', 0, 1)
    execute 'source' f
endfor

call plug#end()

And it works perfect from home directory.

But when I'm running Vim from directory with my project (e.g. cd ~/Dev/my-project && vim) all my configuration and plugins from ~/.vim/*.vim files not works.

Vim uses only configuration from ~/.vimrc. And execute not works

How can I solve this problem? I want to split my Vim config into multiple files

Upvotes: 2

Views: 2943

Answers (3)

sillygenius
sillygenius

Reputation: 1

I think you should use the function globpath(). Just like:

for f in globpath('~/.vim', '*.vim', 0, 1, 0)
    execute 'source' f
endfor

Upvotes: 0

Luc Hermitte
Luc Hermitte

Reputation: 32956

Put your files into $HOME/.vim/plugin, this is what this is for. You may also want to have a look at ftplugins, etc.

I'm quite sure that there is somewhere on SO or on vi.SE a Q/A describing best practices regarding how to split one's config into multiple files.

Upvotes: 4

Azat S.
Azat S.

Reputation: 79

for f in glob('~/.vim/*.vim', 0, 1)
    execute 'source' f
endfor

Upvotes: 6

Related Questions