问题描述
我已将我的 .vimrc 分成几个文件并将它们放入 ~/vimfiles/vimrc.d/
.
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
等
如何通过该目录中的所有文件进行循环,以便我只需在我的 .vimrc 中执行这样的循环:
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
推荐答案
正如 mb14 已经说过的,如果你把它们在 ~/.vim/plugin
中,它们将被自动获取.但是,有关信息,如果您想获取 vimrc.d 目录中的所有文件,您可以这样做(需要相对较新的 Vim):
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
您可能还对自动加载机制感兴趣,在 :help 41.15 中描述
:如果你定义了很多函数,这可以使启动更快一些,因为这些函数只在第一次使用时加载.
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.
这篇关于如何获取目录中的所有vim文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!