Skip to content

rayliwell/nvim-ts-autotag

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nvim-ts-autotag

Use treesitter to autoclose and autorename html tag

It works with:

  • astro
  • glimmer
  • handlebars
  • html
  • javascript
  • jsx
  • markdown
  • php
  • rescript
  • svelte
  • tsx
  • typescript
  • vue
  • xml

Usage

Before        Input         After
------------------------------------
<div           >              <div></div>
<div></div>    ciwspan<esc>   <span></span>
------------------------------------

Setup

Neovim 0.7 and nvim-treesitter to work

User treesitter setup

require'nvim-treesitter.configs'.setup {
  autotag = {
    enable = true,
  }
}

or you can use a set up function

require('nvim-ts-autotag').setup()

Enable update on insert

If you have that issue #19

vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(
    vim.lsp.diagnostic.on_publish_diagnostics,
    {
        underline = true,
        virtual_text = {
            spacing = 5,
            severity_limit = 'Warning',
        },
        update_in_insert = true,
    }
)

Default values

local filetypes = {
    'html', 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'svelte', 'vue', 'tsx', 'jsx', 'rescript',
    'xml',
    'php',
    'markdown',
    'astro', 'glimmer', 'handlebars', 'hbs'
}
local skip_tags = {
  'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'slot',
  'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr','menuitem'
}

Override default values

require'nvim-treesitter.configs'.setup {
  autotag = {
    enable = true,
    enable_rename = true,
    enable_close = true,
    enable_close_on_slash = true,
    filetypes = { "html" , "xml" },
  }
}
-- OR
require('nvim-ts-autotag').setup({
  filetypes = { "html" , "xml" },
})

Sponsor

If you find this plugin useful, please consider sponsoring the project.

Sponsor

About

Use treesitter to auto close and auto rename html tag

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 97.9%
  • Vim Script 1.8%
  • Makefile 0.3%