我最近開始使用AutoComplPop,但是當我寫評論時(當我寫評論時通常不需要自動縮進),我發現彈出令人討厭。如何在註釋中禁用AutoComplPop完成項?
是否有配置選項或快速入侵可以在插入點處於註釋狀態時有效地禁用AutoComplPop?
我最近開始使用AutoComplPop,但是當我寫評論時(當我寫評論時通常不需要自動縮進),我發現彈出令人討厭。如何在註釋中禁用AutoComplPop完成項?
是否有配置選項或快速入侵可以在插入點處於註釋狀態時有效地禁用AutoComplPop?
要在檢查每個光標移動的語法時回答性能問題,我必須自己實現這一點,並將其製作爲OnSyntaxChange插件。
有了這個插件,設置此功能可以在短短三行進行(例如,在.vimrc裏):
call OnSyntaxChange#Install('Comment', '^Comment$', 0, 'i')
autocmd User SyntaxCommentEnterI silent! AcpLock
autocmd User SyntaxCommentLeaveI silent! AcpUnlock
對我來說,對性能的影響是顯着的(根據文件類型和語法),但容忍的。自己試試!
您需要通過鉤子檢查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
有了這個,你應該能夠縫合在一起的解決方案。
如何檢查這會影響vim的性能?它會讓它變慢嗎? –
沒關係;看到我現成的解決方案的其他答案,併爲自己嘗試。 –
謝謝,非常酷的插件 – Josh
我用了一些非常相似的東西,但是用了'NeoComplCacheLock'和'NeoComplCacheUnlock' - 感謝這個偉大的插件! – Matt
如何在python docstring(多行註釋)中實現同樣的效果? – Matt