Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to source all vim files in directory

Tags:

vim

I have split my .vimrc into several files and placed them into ~/vimfiles/vimrc.d/.

Currently I source each file in that directory using exact name:

source ~/vimfiles/vimrc.d/file1.vim source ~/vimfiles/vimrc.d/file2.vim 

etc.

How to make a loop thourgh all files in that directory so i could only have to do such loop in my .vimrc:

for file in ~/vimfiles/vimrc.d/*.vim    source file enfor 
like image 743
devemouse Avatar asked Dec 21 '10 15:12

devemouse


People also ask

Where are my vim files saved?

As said by others: by default it saves in the directory where you started it. But if you aren't aware in which directory you started, then a way to find out is to use the :pwd com in vim. This will output the current directory. That's where vim will store the file.

How do I list files in vim?

In normal mode, type :e then press Space and Ctrl-D. That will list file names in the current directory.

Where is vim directory Linux?

You need to create the . vim folder in your home folder. All plugins will go into the ~/. vim/plugins folder.

What does source do in vim?

The :source command will read the file and interpret the VimScript instructions in it, so this command will effectively load the vim plug-in into your current vim session. Thanks for simple answer.


1 Answers

As mb14 has already said, if you put them in ~/.vim/plugin they will be sourced automatically. For information, however, if you want to source all of the files in your vimrc.d directory, you could do this (requires a relatively recent Vim):

for f in split(glob('~/vimfiles/vimrc.d/*.vim'), '\n')     exe 'source' f endfor 

You may also be interested in the autoload mechanism, described in :help 41.15: if you're defining a lot of functions, this can make start-up a bit quicker as the functions are only loaded the first time they're used.

like image 111
DrAl Avatar answered Sep 21 '22 18:09

DrAl