无法自动获取自定义Vim文件

时间:2014-02-05 10:25:56

标签: bash zsh vim

以下是我的确切设置的回购:https://github.com/Integralist/Fresh-Install/tree/master/Shell

以下是专门针对我的.vimrc文件的链接:https://github.com/Integralist/Fresh-Install/blob/master/Shell/.vimrc

以下是专门针对我的自定义.vim文件的链接:https://github.com/Integralist/Fresh-Install/tree/master/Shell/vim


我正在尝试自动提供一些自定义.vim文件。

为了实现自动化,我意识到我需要将自定义.vim文件按特定顺序排列,因此我必须在文件名前加上一个数字。例如,1.settings.vim

我尝试将它们放在.vim/plugin内但是当我打开Vim时,我的所有插件都没有运行所以我必须手动执行:BundleInstall(或者在启动Vim之前运行vim +BundleInstall)但是当我关闭Vim并再次启动它时插件再次没有运行。因此,除非有办法让Vim自动执行bundle install命令(并且只执行一次,因为每次打开Vim时这样做都是荒谬的)。

相反,我决定尝试通过Vim Script自动获取它们。

以下脚本有效......

set runtimepath+=$DROPBOX/Fresh\ Install/Shell/vim
runtime 1.settings.vim
runtime 2.vundle.vim
runtime 3.mapping.vim
runtime 4.commands.vim

...但不具备可扩展性,因为每次添加新的.vim文件时,我都必须更新脚本。

所以我尝试了另一种方式......

注意:我的.zshrc导出变量DROPBOX并将其设置为我的Dropbox路径。

如果我在新标签中打开Vim(所以我在~/目录中)并执行:echo $DROPBOX,我会看到/Users/markmcdonnell/Dropbox

如果我在一个新标签中打开Vim(所以我在我的~/目录中)并执行:echo isdirectory("$DROPBOX/")我回来0这意味着Vim无法找到该目录。< / p>

但是如果我在一个新标签中打开Vim(所以我在我的~/目录中)并执行:echo isdirectory("/Users/markmcdonnell/Dropbox/")(这与:echo $DROPBOX返回的添加内容相同我得到了一个1,这意味着Vim CAN 找到了该目录。

因此,Vim Script如何解释手动输入的路径以及从环境变量扩展的路径是不正确的。

我尝试过的示例脚本是......

if isdirectory("$DROPBOX/Fresh Install/Shell/vim")
  for file in split(globpath('$DROPBOX/Fresh Install/Shell/vim/', '*.vim'), '\n')
    execute 'source ' file
  endfor
endif

...但是这些文件并非来源,而且当我意识到在Vim中isdirectory("$DROPBOX/Fresh Install/Shell/vim")行返回0时。

我无法手动输入完整路径,因为我在不同的计算机上同步我的文件,因此路径发生了变化。

所以我将if语句修改为:isdirectory(expand('%:p:h').'/vim'),当在Vim中运行时返回1(这是我cd进入Dropbox文件夹/Fresh Install/并打开/Shell/.vimrc文件)。

因此,:echo expand('%:p:h')返回/Users/markmcdonnell/Dropbox/Fresh Install/Shell,因此它设法找到了正确的目录。

但这再次没有用。

我还尝试了另一种格式(但基本上是相同的过程,只是写得更简洁):" execute join(map(split(glob("$DROPBOX/Fresh Install/Shell/vim/*.vim"), "\n"), '"source " . v:val'), "\n")

再次无效。

然后我试了......

for file in split(globpath('$DROPBOX/Fresh Install/Shell/vim/', '*.vim'), '\n')
  execute 'source ' . file
endfor

...但是没有检查文件夹是否存在(因为它应该始终存在)。

但现在我收到错误:Only one file name allowed: source /Users/markmcdonnell/Dropbox/Fresh Install/Shell/vim/1.settings.vim

所以看起来它几乎正常工作但是路径中的空间可能导致脚本认为当它只有一个时有两个参数。

我回到了之前的(非简洁版)并尝试引用命令:

execute 'source ' . "file"execute 'source ' . "$file"以及execute "source $file"

但是,这些都没有奏效。

我确信我错过了一些非常简单的东西,但任何帮助都会受到赞赏。

UPDATE:

let files = split(glob("$DROPBOX/Fresh Install/Shell/vim/*.vim"), "\n")
let mapped = map(files, '"source " . v:val')
execute join(mapped, "\n")

这是与以前相同的命令,但稍微扩展一下。

我想我需要能够在v:val周围获得一组双引号,这样当命令为execute时,文件名中的空格就不会引起问题。

更新2:

以下是运行:verbose set rtp?

的结果
runtimepath=
~/.vim/bundle/vundle
~/.vim/bundle/ctrlp.vim
~/.vim/bundle/tomorrow-night-vim
~/.vim/bundle/vim-markdown
~/.vim/bund le/vim-cucumber
~/.vim/bundle/vim-misc
~/.vim/bundle/tagbar
~/.vim/bundle/YouCompleteMe
~/.vim/bundle/vim-repeat
~/.vim/bundle/vim -commentary
~/.vim/bundle/ack.vim
~/.vim/bundle/vim-endwise
~/.vim/bundle/vim-airline
~/.vim/bundle/tmuxline.vim
~/.vim/bundle/web api-vim
~/.vim/bundle/Gist.vim
~/.vim/bundle/vim-fugitive
~/.vim/bundle/emmet-vim
~/.vim/bundle/rename.vim
~/.vim/bundle/vim-gitgu tter
~/.vim/bundle/nerdtree
~/.vim/bundle/vim-haml
~/.vim/bundle/vim-surround
~/.vim/bundle/html5.vim
~/.vim/bundle/tabular
~/.vim /bundle/camelcasemotion
~/.vim
/usr/local/share/vim/vimfiles
/usr/local/share/vim/vim74
/usr/local/share/vim/vimfiles/after
~/.vim /after
~/Dropbox/Fresh Install/Shell/vim
~/.vim/bundle/vundle/after
~/.vim/bundle/ctrlp.vim/after
~/.vim/bundle/tomorrow-night-vim
/after
~/.vim/bundle/vim-markdown/after
~/.vim/bundle/vim-cucumber/after
~/.vim/bundle/vim-misc/after
~/.vim/bundle/tagbar/after

Last set from ~/Dropbox/Fresh Install/Shell/.vim/bundle/vundle/autoload/vundle/config.vim

这是我删除以下代码段后的结果......

set runtimepath+=$DROPBOX/Fresh\ Install/Shell/vim
runtime 1.settings.vim
runtime 2.vundle.vim
runtime 3.mapping.vim
runtime 4.commands.vim

...我正在使用它来手动获取vim文件。

值得注意的是,BufOnly.vim内的~/.vim/plugin文件正在自动加载,因此其他.vim文件不是很奇怪

更新3

以下是运行:scriptnames

的结果
1: ~/.vimrc
2: ~/Dropbox/Fresh Install/Shell/vim/1.settings.vim
3: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/syntax/syntax.vim
4: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/syntax/synload.vim
5: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/syntax/syncolor.vim
6: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/filetype.vim
7: ~/Dropbox/Fresh Install/Shell/vim/2.vundle.vim
8: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/ftoff.vim
9: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vundle/autoload/vundle.vim
10: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vundle/autoload/vundle/config.vim
11: ~/Dropbox/Fresh Install/Shell/.vim/bundle/tomorrow-night-vim/colors/tomorrow-night-bright.vim
12: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-markdown/ftdetect/markdown.vim
13: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-cucumber/ftdetect/cucumber.vim
14: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-haml/ftdetect/haml.vim
15: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/ftplugin.vim
16: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/indent.vim
17: ~/Dropbox/Fresh Install/Shell/vim/3.mapping.vim
18: ~/Dropbox/Fresh Install/Shell/vim/4.commands.vim
19: ~/Dropbox/Fresh Install/Shell/.vim/bundle/ctrlp.vim/plugin/ctrlp.vim
20: ~/Dropbox/Fresh Install/Shell/.vim/bundle/ctrlp.vim/autoload/ctrlp/mrufiles.vim
21: ~/Dropbox/Fresh Install/Shell/.vim/bundle/tagbar/plugin/tagbar.vim
22: ~/Dropbox/Fresh Install/Shell/.vim/bundle/YouCompleteMe/plugin/youcompleteme.vim
23: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-commentary/plugin/commentary.vim
24: ~/Dropbox/Fresh Install/Shell/.vim/bundle/ack.vim/plugin/ack.vim
25: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-endwise/plugin/endwise.vim
26: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/plugin/airline.vim
27: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline.vim
28: ~/Dropbox/Fresh Install/Shell/.vim/bundle/tmuxline.vim/plugin/tmuxline.vim
29: ~/Dropbox/Fresh Install/Shell/.vim/bundle/Gist.vim/plugin/gist.vim
30: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-fugitive/plugin/fugitive.vim
31: ~/Dropbox/Fresh Install/Shell/.vim/bundle/emmet-vim/plugin/emmet.vim
32: ~/Dropbox/Fresh Install/Shell/.vim/bundle/rename.vim/plugin/rename.vim
33: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-gitgutter/plugin/gitgutter.vim
34: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/plugin/NERD_tree.vim
35: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/autoload/nerdtree.vim
36: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/lib/nerdtree/path.vim
37: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/lib/nerdtree/menu_controller.vim
38: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/lib/nerdtree/menu_item.vim
39: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/lib/nerdtree/key_map.vim
40: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/lib/nerdtree/bookmark.vim
41: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/lib/nerdtree/tree_file_node.vim
42: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/lib/nerdtree/tree_dir_node.vim
43: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/lib/nerdtree/opener.vim
44: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/lib/nerdtree/creator.vim
45: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/nerdtree_plugin/exec_menuitem.vim
46: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/nerdtree_plugin/fs_menu.vim
47: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-surround/plugin/surround.vim
48: ~/Dropbox/Fresh Install/Shell/.vim/bundle/tabular/plugin/Tabular.vim
49: ~/Dropbox/Fresh Install/Shell/.vim/bundle/camelcasemotion/plugin/camelcasemotion.vim
50: ~/Dropbox/Fresh Install/Shell/.vim/plugin/1.settings.vim
51: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/syntax/nosyntax.vim
52: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/init.vim
53: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/parts.vim
54: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/extensions.vim
55: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/extensions/quickfix.vim
56: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/extensions/ctrlp.vim
57: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/extensions/hunks.vim
58: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/extensions/tagbar.vim
59: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/extensions/branch.vim
60: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/extensions/whitespace.vim
61: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/section.vim
62: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/highlighter.vim
63: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/themes/tomorrow.vim
64: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/themes.vim
65: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/builder.vim
66: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/util.vim
67: ~/Dropbox/Fresh Install/Shell/.vim/bundle/vim-airline/autoload/airline/extensions/default.vim
68: ~/Dropbox/Fresh Install/Shell/.vim/plugin/2.vundle.vim
69: ~/Dropbox/Fresh Install/Shell/.vim/plugin/3.mapping.vim
70: ~/Dropbox/Fresh Install/Shell/.vim/plugin/4.commands.vim
71: ~/Dropbox/Fresh Install/Shell/.vim/plugin/BufOnly.vim
72: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/plugin/getscriptPlugin.vim
73: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/plugin/gzip.vim
74: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/plugin/matchparen.vim
75: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/plugin/netrwPlugin.vim
76: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/plugin/rrhelper.vim
77: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/plugin/spellfile.vim
78: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/plugin/tarPlugin.vim
79: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/plugin/tohtml.vim
80: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/plugin/vimballPlugin.vim
81: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/plugin/zipPlugin.vim
82: ~/Dropbox/Fresh Install/Shell/.vim/bundle/tabular/after/plugin/TabularMaps.vim
83: ~/Dropbox/Fresh Install/Shell/.vim/bundle/tabular/autoload/tabular.vim
84: ~/Dropbox/Fresh Install/Shell/.vim/bundle/YouCompleteMe/autoload/youcompleteme.vim
85: ~/Dropbox/Fresh Install/Shell/.vim/bundle/tagbar/autoload/tagbar.vim
86: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/scripts.vim
87: ~/Dropbox/Fresh Install/Shell/.vim/bundle/nerdtree/syntax/nerdtree.vim
88: ~/Dropbox/Fresh Install/Shell/.vim/bundle/ctrlp.vim/autoload/ctrlp/utils.vim
89: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/ftplugin/vim.vim
90: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/indent/vim.vim
91: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/syntax/vim.vim
92: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/syntax/perl.vim
93: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/syntax/pod.vim
94: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/syntax/ruby.vim
95: /usr/local/Cellar/vim/7.4.052/share/vim/vim74/syntax/python.vim

同样,根据UPDATE 2,在我手动获取单独的vim脚本文件之前,没有我在.vimrc文件中的任何代码。我.vimrc运行:scriptnames时唯一的代码是......

if filereadable(".vimlocal")
  source .vimlocal
endif

...但有趣的是,您可以在上面看到~/Dropbox/Fresh Install/Shell/vim/中的文件正在加载(如果这是:scriptnames显示的那个?)。请注意,~/Dropbox/Fresh Install/Shell/vim/中的文件是~/.vim/plugin

中文件的副本

3 个答案:

答案 0 :(得分:0)

假设$FOO指向真实的现有目录......

:echo isdirectory("$FOO")

返回0,因为使用了字符串$FOO而您没有$FOO目录。

:echo isdirectory($FOO)

返回1,因为使用了$FOO的值而不是字符串$FOO


我可以补充一点,我觉得你的设置不必要复杂吗?

答案 1 :(得分:0)

我到目前为止

  

我尝试将它们放在.vim / plugin中,但是当我打开Vim时,我的插件都没有运行

我宁愿修理一个爆胎而不是重新发明轮子。

.vim/plugin,您的意思是~/.vim/plugin/,以便您的文件

~/.vim/plugin/1.settings.vim

等等?如果是这样,如果你在类似* NIX的系统上,那么这应该可行。请参阅:help load-plugins,原因是vim可能会跳过加载插件文件的步骤。试试:verbose set rtp?,了解您是否应该使用~/.vim或其他内容。使用:scriptnames确保他们正在加载 - 可能还有其他一些解释,说明您所看到的内容。

更新(根据您的评论):

我没想到~/.vim/plugin会被列为'rtp'的一部分。我确实希望列出~/.vim,而且确实如此。根据{{​​1}},路径的:help load-plugins部分已添加。

您说plugin/来自BufOnly.vim,但它列为~/.vim/plugin/。您是否建立了从71: ~/Dropbox/Fresh Install/Shell/.vim/plugin/BufOnly.vim~/.vim的sym链接?您想要的文件~/Dropbox/Fresh Install/Shell/.vim/1.settings.vim位于同一目录中,根据4.commands.vim的输出,它们也来源(第50和68-70行,就在{ {1}})。

我在这里看不到任何神秘的东西。您要获取的文件来源。如果他们没有你想要的效果,那就去别处寻找解释。

顺便说一句,:scriptnamesBufOnly.vim之间共有大约17个文件。我很确定1.settings.vim必须触发这些其他文件。

答案 2 :(得分:0)

我有类似的问题。符号链接在〜/ .vim / plugin中无法识别,因此您将不得不在其中复制文件,而不是向包含所有文件的“ git”文件夹中创建符号链接。

相关问题