nvim: auto-closing html tags

This commit is contained in:
2026-09-27 07:33:01 +02:00
parent dc1a319165
commit 3c0fc3ae6b
2 changed files with 40 additions and 0 deletions
+7
View File
@@ -207,6 +207,13 @@ A feature-rich Neovim setup optimized for Python, JSON, and CSV development.
- **Linting**: ESLint LSP (fix with `<leader>fx`, or use `<leader>fA` for fix-all actions) - **Linting**: ESLint LSP (fix with `<leader>fx`, or use `<leader>fA` for fix-all actions)
- **Formatting**: Prettier via `<leader>lf` - **Formatting**: Prettier via `<leader>lf`
### HTML (.html)
- **Auto-close tags**: typing `<div` + `>` inserts `</div>` automatically (`nvim-ts-autotag`)
- **Auto-rename tags**: `ciw` on an opening tag renames the matching closing tag
- **Enter between tags**: expands to indented lines via Treesitter indenting
- **Also applies to**: `.vue`, `.tsx`, `.jsx`, `.svelte`, `.astro`, `.xml`, `.php`, `.hbs`
- **Requires** the Treesitter parser for the filetype (already auto-installed for html/vue/tsx)
### CSV (.csv) ### CSV (.csv)
- **Treesitter**: Syntax highlighting - **Treesitter**: Syntax highlighting
- **No wrap**: Full row visibility - **No wrap**: Full row visibility
@@ -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,
}