nvim: auto-closing html tags
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
--[[
|
||||
TS-AUTOTAG.LUA
|
||||
|
||||
Auto-close and auto-rename HTML/XML-style tags via Treesitter.
|
||||
|
||||
Why this exists: nvim-autopairs (see autopairs.lua) only handles brackets,
|
||||
quotes and endwise pairs -- it never creates a closing tag. Its only
|
||||
HTML-aware rule fires on <CR> when a close tag ALREADY exists after the
|
||||
cursor, so it can re-indent a pair but cannot create one. This plugin
|
||||
fills that gap: typing `<div` + `>` yields `<div></div>` with the cursor
|
||||
in between, and `ciw` on an opening tag renames its closing counterpart.
|
||||
|
||||
Requires the matching Treesitter parsers. `html`, `vue`, `tsx` and
|
||||
`javascript` are already in treesitter.lua's `ensure_installed` list, and
|
||||
the plugin no-ops in filetypes whose parser is missing, so a fresh machine
|
||||
just needs a restart after the parsers are installed.
|
||||
]]
|
||||
|
||||
return {
|
||||
"windwp/nvim-ts-autotag",
|
||||
-- Load events recommended upstream. BufReadPre/BufNewFile is sufficient
|
||||
-- because the plugin only acts once a filetype's parser is available.
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
config = function()
|
||||
require("nvim-ts-autotag").setup({
|
||||
opts = {
|
||||
enable_close = true, -- `<div` + `>` -> `<div></div>`
|
||||
enable_rename = true, -- `ciw` on the open tag renames the close tag
|
||||
enable_close_on_slash = false, -- a trailing `</` does not autoclose
|
||||
},
|
||||
})
|
||||
end,
|
||||
}
|
||||
Reference in New Issue
Block a user