我最近开始使用AutoComplPop,但是当我写评论时我发现弹出窗口很烦人(因为我在写评论时通常不需要自动完成)。
当插入点在评论中时,是否有配置选项或快速破解可以有效地禁用 AutoComplPop?
我最近开始使用AutoComplPop,但是当我写评论时我发现弹出窗口很烦人(因为我在写评论时通常不需要自动完成)。
当插入点在评论中时,是否有配置选项或快速破解可以有效地禁用 AutoComplPop?
您需要通过挂钩检查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
有了这个,你应该能够拼凑出一个解决方案。
为了回答在每次光标移动时检查语法时的性能问题,我必须自己实现它,并将其放入OnSyntaxChange插件中。
使用这个插件,只需三行即可完成设置(例如在 .vimrc 中):
call OnSyntaxChange#Install('Comment', '^Comment$', 0, 'i')
autocmd User SyntaxCommentEnterI silent! AcpLock
autocmd User SyntaxCommentLeaveI silent! AcpUnlock
对我来说,性能影响是显而易见的(取决于文件类型和语法),但可以容忍。自己试试吧!