Reputation: 23134
I was reading the .vimrc from spf13-vim on github, and there was something I didn't understand:
" 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'
endif
What does the count()
function do here?
Upvotes: 0
Views: 606
Reputation: 172648
:help count()
tells you:
Return the number of times an item with value {expr} appears in |List| or |Dictionary| {comp}.
So this counts how often the value (e.g. 'snipmate'
) occurs in the List variable g:spf13_bundle_groups
. The resulting number is then interpreted as a Boolean (0 = false, everything else = true).
A more canonical (and maybe a little bit faster) way would be to use index()
instead:
if index(g:spf13_bundle_groups, 'snipmate') != -1
...
Upvotes: 1
Reputation: 195179
check if the item (snipmate or neocomplcache...) exists in the g:spf13_bundle_groups
.
Upvotes: 1