Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ts-autotag.nvim

Introduction

A minimalist Neovim plugin that auto closes & renames html/jsx elements without setting keymaps

Caution

Do not lazy load this plugin, it breaks correct initialization order meaning it may not work at all. Plugin is already lazy loaded by default. More info :h lua-plugin-lazy

Tip

After plugin install run :checkhealth ts-autotag to check if parsers are installed correctly

Examples

Auto close tag

auto close tag gif

Manual rename tag

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)

Or you can use a user command :TsTagRename

manual rename tag gif

Auto live rename tag

Note

Feature is not enabled by default, enable with auto_rename.enabled = true

auto rename tag gif

Install

Install with your favorite plugin manager

Calling setup() is optional, only if you want to override default settings, for example enabling auto live rename

Plugin is lazy loaded by default

Configuration

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,

	-- plugin will be initialized on these filetypes
	filetypes = {
		"typescript",
		"javascript",
		"typescriptreact",
		"javascriptreact",
		"xml",
		"html",
		"templ",
		"php",
	},

	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",
		},
	},
	-- disable plugin on some buffers
	should_attach = function(buf) return true end
}

Differences between nvim-ts-autotag

  • 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

About

A minimalist neovim plugin to close & rename html/jsx elements with the power of treesitter

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages