首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >vimscript中的Count()函数

vimscript中的Count()函数
EN

Stack Overflow用户
提问于 2013-08-07 18:11:01
回答 2查看 487关注 0票数 0

我在github上阅读spf13-vim中的.vimrc,有一件事我不明白:

代码语言:javascript
复制
" 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

count()函数在这里做什么?

EN

回答 2

Stack Overflow用户

发布于 2013-08-07 18:18:28

检查项目(snipmate或neComplache...)存在于g:spf13_bundle_groups中。

票数 1
EN

Stack Overflow用户

发布于 2013-08-07 18:25:52

:help count()告诉您:

返回值为{expr}的项目在|列表|或|字典| {comp}中出现的次数。

因此,这计算了值(例如'snipmate')在列表变量g:spf13_bundle_groups中出现的频率。然后将得到的数字解释为布尔值(0 = false,其他所有内容= true)。

一种更规范(也许更快一点)的方法是使用index()

代码语言:javascript
复制
if index(g:spf13_bundle_groups, 'snipmate') != -1
    ...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18100601

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档