[英]Inserting non-modifiable text to a vim buffer
有什么方法可以將不可修改的文本插入可修改的緩沖區。 如果可能,我也想更改插入文本的語法突出顯示。
示例(我要實現的目標):
緩沖區的內容:
text...
/* this is a script which can be replaced
the second line of the script */
other text...
我突出顯示第二行和第三行,並運行我的插件,該插件將這些行替換為不可修改的文本。
text...
[non-modifiable text]
other text...
如果我再次在不可修改的文本上運行插件,則它將替換回其原始內容。
text...
/* this is a script which can be replaced
the second line of the script */
other text...
您不能強制Vim命令不更改某些行。 緩沖區只能完全“鎖定”,但要清除'modifiable'
選項。
您可以達到的最佳效果是還原這些行的原始內容。 可以通過:autocmd
完成。 合適的觸發事件是BufWritePre
; 可以進行更改,但是將在保留緩沖區之前立即還原。 演示:
:autocmd BufWritePre <buffer> call setline(2, '[non-modifiable text]')
對於突出顯示,您可以擴展語法突出顯示 ,或使用語法之上的(window-local) :match
:
:match NonText /^\[non-modifiable text\]$/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.