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在此插件上的工作。
如果您发现此插件有用,请考虑赞助该项目。
赞助