我在github上阅读spf13-vim中的.vimrc,有一件事我不明白:
" Snippets & AutoComplete
if count(g:spf13_bundle_groups, 'snipmate')
Bundle 'garbas/vim-snipmate'
Bundle 'honza/vim-snippets'
" Source support_function.vim to support vim-snippets.
if filereadable(expand("~/.vim/bundle/vim-snippets/snippets/support_functions.vim"))
source ~/.vim/bundle/vim-snippets/snippets/support_functions.vim
endif
elseif count(g:spf13_bundle_groups, 'neocomplcache')
Bundle 'Shougo/neocomplcache'
Bundle 'Shougo/neosnippet'
Bundle 'honza/vim-snippets'
elseif count(g:spf13_bundle_groups, 'neocomplete')
Bundle 'Shougo/neocomplete.vim.git'
Bundle 'Shougo/neosnippet'
Bundle 'honza/vim-snippets'
endifcount()函数在这里做什么?
发布于 2013-08-07 18:18:28
检查项目(snipmate或neComplache...)存在于g:spf13_bundle_groups中。
发布于 2013-08-07 18:25:52
:help count()告诉您:
返回值为{expr}的项目在|列表|或|字典| {comp}中出现的次数。
因此,这计算了值(例如'snipmate')在列表变量g:spf13_bundle_groups中出现的频率。然后将得到的数字解释为布尔值(0 = false,其他所有内容= true)。
一种更规范(也许更快一点)的方法是使用index():
if index(g:spf13_bundle_groups, 'snipmate') != -1
...https://stackoverflow.com/questions/18100601
复制相似问题