【问题标题】:How to disable AutoComplPop completions in comments?如何在评论中禁用 AutoComplPop 完成?
【发布时间】:2012-05-30 05:04:13
【问题描述】:

我最近开始使用AutoComplPop,但我在编写 cmets 时发现弹出窗口很烦人(因为我在编写评论时通常不需要自动完成)。

当插入点在评论中时,是否有可以有效禁用 AutoComplPop 的配置选项或快速破解?

【问题讨论】:

    标签: vim autocomplete


    【解决方案1】:

    为了回答在每次光标移动时检查语法时的性能问题,我必须自己实现它,并将其放入OnSyntaxChange 插件中。

    使用此插件,只需三行即可完成设置(例如在 .vimrc 中):

    call OnSyntaxChange#Install('Comment', '^Comment$', 0, 'i')
    autocmd User SyntaxCommentEnterI silent! AcpLock
    autocmd User SyntaxCommentLeaveI silent! AcpUnlock
    

    对我来说,性能影响是显而易见的(取决于文件类型和语法),但可以忍受。自己试试吧!

    【讨论】:

    • 我使用了非常相似的东西,但使用了 NeoComplCacheLockNeoComplCacheUnlock -- 感谢伟大的插件!
    • 如何在 python 文档字符串(多行注释)中实现相同的效果?
    • @MattBall:只要找出语法组的名称(可能是String),然后在上面的sn-p中使用它而不是Comment'
    【解决方案2】:

    您需要通过 CursorMovedI 的钩子检查您当前是否在评论中,然后可以使用 AutoComplPop 的 :AcpLock 暂时禁用它。 (离开 cmets 后使用 :AcpUnlock 撤消。)

    检测各种文件类型的 cmets 最好通过查询语法高亮来完成;这样,您就可以从现有文件类型的语法定义中受益。

    这是一个sn-p:

    function! IsOnSyntaxItem( syntaxItemPattern )
        " Taking the example of comments:
        " Other syntax groups (e.g. Todo) may be embedded in comments. We must thus
        " check whole stack of syntax items at the cursor position for comments.
        " Comments are detected via the translated, effective syntax name. (E.g. in
        " Vimscript, 'vimLineComment' is linked to 'Comment'.)
        for l:id in synstack(line('.'), col('.'))
            let l:actualSyntaxItemName = synIDattr(l:id, 'name')
            let l:effectiveSyntaxItemName = synIDattr(synIDtrans(l:id), 'name')
            if l:actualSyntaxItemName =~# a:syntaxItemPattern || l:effectiveSyntaxItemName =~# a:syntaxItemPattern
                return 1
            endif
        endfor
        return 0
    endfunction
    

    有了这个,你应该能够拼凑出一个解决方案。

    【讨论】:

    • 检查这个如何影响 vim 性能?它会慢很多吗?
    • 没关系;请参阅我的其他答案以获取现成的解决方案,然后自己尝试一下。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    相关资源
    最近更新 更多