将 Vim 配置拆分为多个文件
Splitting Vim config into multiple files
这是我的配置的一部分:
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()
它在主目录下运行完美。
但是当我从我的项目目录(例如 cd ~/Dev/my-project && vim
)运行 Vim 时,我所有来自 ~/.vim/*.vim
文件的配置和插件都不起作用。
Vim 仅使用 ~/.vimrc
中的配置。 execute
无效
我该如何解决这个问题?我想将我的 Vim 配置分成多个文件
for f in glob('~/.vim/*.vim', 0, 1)
execute 'source' f
endfor
将您的文件放入$HOME/.vim/plugin
,这就是它的用途。您可能还想看看 ftplugins 等
我很确定在 SO 或 vi.SE 上有某个地方 Q/A 描述了关于如何将一个配置拆分为多个文件的最佳实践。
我认为你应该使用函数 globpath()。就像:
for f in globpath('~/.vim', '*.vim', 0, 1, 0)
execute 'source' f
endfor
这是我的配置的一部分:
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()
它在主目录下运行完美。
但是当我从我的项目目录(例如 cd ~/Dev/my-project && vim
)运行 Vim 时,我所有来自 ~/.vim/*.vim
文件的配置和插件都不起作用。
Vim 仅使用 ~/.vimrc
中的配置。 execute
无效
我该如何解决这个问题?我想将我的 Vim 配置分成多个文件
for f in glob('~/.vim/*.vim', 0, 1)
execute 'source' f
endfor
将您的文件放入$HOME/.vim/plugin
,这就是它的用途。您可能还想看看 ftplugins 等
我很确定在 SO 或 vi.SE 上有某个地方 Q/A 描述了关于如何将一个配置拆分为多个文件的最佳实践。
我认为你应该使用函数 globpath()。就像:
for f in globpath('~/.vim', '*.vim', 0, 1, 0)
execute 'source' f
endfor