A minimalist Neovim plugin that auto closes & renames html/jsx elements without setting keymaps
Note
Keymaps are not set by default, you have to set them yourself like so
vim.keymap.set("n", "<leader>rn", function()
-- it returns success status, thus you can fallback like so
if not require("ts-autotag").rename() then
vim.lsp.buf.rename()
end
end)
Warning
Feature is VERY experimental and DISABLED BY DEFAULT, uses extmarks to keep track of tags and replaces them, using TS is not enough for multi language support. As it doesn't cover all edge-cases I recommend using the manual method, however if you really want live replace you can enable it.
With lazy.nvim
{
"tronikelis/ts-autotag.nvim",
opts = {},
-- ft = {}, optionally you can load it only in jsx/html
event = "VeryLazy",
}
Default config
{
opening_node_types = {
-- templ
"tag_start",
-- xml,
"STag",
-- html
"start_tag",
-- jsx
"jsx_opening_element",
},
identifier_node_types = {
-- html
"tag_name",
"erroneous_end_tag_name",
-- xml,
"Name",
-- jsx
"member_expression",
"identifier",
-- templ
"element_identifier",
},
disable_in_macro = true,
auto_close = {
enabled = true,
},
auto_rename = {
enabled = false,
closing_node_types = {
-- jsx
"jsx_closing_element",
-- xml,
"ETag",
-- html
"end_tag",
"erroneous_end_tag",
-- templ
"tag_end",
},
},
}
- A much more "dumb" and simple solution which just checks child node types under cursor
- Does not override any keymaps,
nvim-ts-autotag
overrides>
keymap which could break other plugins