How to disable AutoComplPop completions in comments?

老子叫甜甜 提交于 2019-12-25 06:39:26

问题


I've recently started using AutoComplPop, but I find the popup annoying when I'm writing comments (as I usually don't need autocomplition when writing a comment).

Is there a configuration option or a quick hack that can effectively disable AutoComplPop when the insertion point is in a comment?


回答1:


To answer the question of performance when checking the syntax on every cursor move, I had to implement this myself, and made this into the OnSyntaxChange plugin.

With this plugin, setting this up can be done in just three lines (e.g. in .vimrc):

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

For me, the performance impact is noticeable (depending on the filetype and syntax), but tolerable. Try for yourself!




回答2:


You need to check via a hook into CursorMovedI that you're currently in a comment, and can then use AutoComplPop's :AcpLock to disable it temporarily. (And undo with :AcpUnlock once you move out of comments.)

Detecting comments for various filetypes is best done by querying the syntax highlighting; this way, you benefit from the syntax definitions of existing filetypes.

Here's a snippet for this:

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

With this, you should be able to stitch together a solution.



来源:https://stackoverflow.com/questions/10723499/how-to-disable-autocomplpop-completions-in-comments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!