nvim ts autotag
1.0.0
使用TreeTitter自動亮相和自動名稱HTML標籤
它與:
還有更多
Before Input After
------------------------------------
<div > <div></div>
<div></div> ciwspan<esc> <span></span>
------------------------------------
需要Nvim 0.9.5
及以上。
請注意,除非您為給定的Filetype安裝了Treestter Parsers(如html
),否則nvim-ts-autotag
將無法工作。請參閱NVIM-Treesitter安裝解析器。
require ( ' nvim-ts-autotag ' ). setup ({
opts = {
-- Defaults
enable_close = true , -- Auto close tags
enable_rename = true , -- Auto rename pairs of tags
enable_close_on_slash = false -- Auto close on trailing </
},
-- Also override individual filetype configs, these take priority.
-- Empty by default, useful if one of the "opts" global settings
-- doesn't work well in a specific filetype
per_filetype = {
[ " html " ] = {
enable_close = false
}
}
})
警告
如果您要通過nvim-treesitter.configs
進行設置,則已棄用!請遷移到新的方式。它將在1.0.0
中刪除。
對於那些通過插件管理器(例如lazy.nvim)使用懶惰加載的人來說,懶惰加載並不是特別需要的。 nvim-ts-autotag
在選擇何時需要加載方面有效。如果您仍然堅持懶惰的nvim-ts-autotag
,那麼使用兩個好的事件是BufReadPre
& BufNewFile
。
假設有一種nvim-ts-autotag
目前不支持的語言,您想在配置中支持它。雖然您在更改上游的作者偏愛,但也許您寧願不是嗎?
例如,如果您的treeTitter查詢中具有非常相似的佈局的語言與html
,則可以添加類似的別名:
require ( ' nvim-ts-autotag ' ). setup ({
aliases = {
[ " your language here " ] = " html " ,
}
})
-- or
local TagConfigs = require ( " nvim-ts-autotag.config.init " )
TagConfigs : add_alias ( " your language here " , " html " )
這將根據給定語言中的html
配置規則使nvim-ts-autotag
關閉標籤。
但是,如果出於任何原因而破裂,例如上游樹木樹更改其節點名稱,現在nvim-ts-autotag
提供了不再工作的默認查詢。
害怕不要!您可以直接擴展並覆蓋現有配置。例如,假設xml
的開始和結束標籤模式已更改。我們可以直接覆蓋xml
配置:
local TagConfigs = require ( " nvim-ts-autotag.config.init " )
TagConfigs : update ( TagConfigs : get ( " xml " ): override ( " xml " , {
start_tag_pattern = { " STag " },
end_tag_pattern = { " ETag " },
}))
實際上,這幾乎是我們在nvim-ts-autotag
的內部初始化階段所做的。
如果您有第19期
vim . lsp . handlers [ ' textDocument/publishDiagnostics ' ] = vim . lsp . with (
vim . lsp . diagnostic . on_publish_diagnostics ,
{
underline = true ,
virtual_text = {
spacing = 5 ,
severity_limit = ' Warning ' ,
},
update_in_insert = true ,
}
)
感謝@PriceHiller在此插件上的工作。
如果您發現此插件有用,請考慮贊助該項目。
贊助