如何在评论中禁用AutoComplPop完成?

时间:2012-05-23 15:45:57

标签: vim autocomplete

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

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

2 个答案:

答案 0 :(得分:2)

您需要通过挂钩检查您当前正在评论的CursorMovedI,然后可以使用AutoComplPop的:AcpLock暂时禁用它。 (一旦退出评论,请撤消:AcpUnlock。)

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

这是一个代码片段:

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

有了这个,您应该能够将解决方案拼接在一起。

答案 1 :(得分:2)

要在每次光标移动时检查语法时回答性能问题,我必须自己实现,并将其转换为OnSyntaxChange插件。

使用这个插件,设置它只需要三行(例如.vimrc):

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

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