From 3c0fc3ae6ba9f6dd7e9227ddf5f769e4e49d42db Mon Sep 17 00:00:00 2001 From: Mathias Date: Sun, 27 Sep 2026 07:33:01 +0200 Subject: [PATCH] nvim: auto-closing html tags --- term/.config/nvim/README.md | 7 +++++ term/.config/nvim/lua/plugins/ts-autotag.lua | 33 ++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 term/.config/nvim/lua/plugins/ts-autotag.lua diff --git a/term/.config/nvim/README.md b/term/.config/nvim/README.md index 8c939e9..d04f0f3 100644 --- a/term/.config/nvim/README.md +++ b/term/.config/nvim/README.md @@ -207,6 +207,13 @@ A feature-rich Neovim setup optimized for Python, JSON, and CSV development. - **Linting**: ESLint LSP (fix with `fx`, or use `fA` for fix-all actions) - **Formatting**: Prettier via `lf` +### HTML (.html) +- **Auto-close tags**: typing `` inserts `` 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) - **Treesitter**: Syntax highlighting - **No wrap**: Full row visibility diff --git a/term/.config/nvim/lua/plugins/ts-autotag.lua b/term/.config/nvim/lua/plugins/ts-autotag.lua new file mode 100644 index 0000000..76f433f --- /dev/null +++ b/term/.config/nvim/lua/plugins/ts-autotag.lua @@ -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 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 `` yields `
` 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, -- `` -> `
` + enable_rename = true, -- `ciw` on the open tag renames the close tag + enable_close_on_slash = false, -- a trailing `