nvim-ts-autotag icon indicating copy to clipboard operation
nvim-ts-autotag copied to clipboard

Don't work.

Open seriiserii825 opened this issue 2 years ago • 29 comments

Install plugins in neovim + lua.

  use "nvim-treesitter/nvim-treesitter"
  use "windwp/nvim-ts-autotag"

Create a file tree-sitter.lua and include in init.lua

require 'nvim-treesitter.configs'.setup {
  -- A list of parser names, or "all"
  ensure_installed = { "lua" },
  -- Install parsers synchronously (only applied to `ensure_installed`)
  sync_install = false,
  
  autotag = {
    enable = true,
    filetypes = { "html", "xml", "php", "vue" },
  },

  highlight = {
    -- `false` will disable the whole extension
    enable = true,

    -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
    -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
    -- the name of the parser)
    -- list of language that will be disabled
    disable = { "c", "rust" },

    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },
}

In html file i can't rename html tag.

seriiserii825 avatar May 27 '22 12:05 seriiserii825

not working for me either, no errors, using the default set up. I am on a new version of NeoVim though.

neovim: NVIM v0.8.0-dev+406-g502f03fc0
windwp/nvim-ts-autotag: latest master

tomspeak avatar Jun 20 '22 16:06 tomspeak

Same here.

tiagaoalb avatar Jun 21 '22 13:06 tiagaoalb

Have you ran :TSInstall html?

YoungeonLee avatar Jul 04 '22 04:07 YoungeonLee

Have you ran :TSInstall html?

@YoungeonLee I have, but still the same.

I'm trying to run on LunarVim.

$ lvim -v
NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by [email protected]

danilobjr avatar Jul 29 '22 20:07 danilobjr

@danilobjr Try adding

lvim.builtin.treesitter.autotag.enable = true 

to your config. If that doesn't work, try running :TSEnable autotag.

YoungeonLee avatar Jul 30 '22 04:07 YoungeonLee

lvim.builtin.treesitter.autotag.enable = true

@YoungeonLee This works like a charm now. Thank you so much! 🎉

danilobjr avatar Aug 01 '22 17:08 danilobjr

require("nvim-treesitter.configs").setup({ ensure_installed = { "c", "c_sharp", "css", "go", "graphql", "html", "json", "http", "javascript", "lua", "markdown", "python", "rust", "typescript", "yaml", "bash", "comment", "java", }, sync_install = false, highlight = { enable = true, additional_vim_regex_highlighting = true, }, indent = { enable = true, disable = { "yaml" } }, rainbow = { enable = true, extended_mode = true, max_file_lines = nil, }, context_commentstring = { enable = true, enable_autocmd = false, }, autotag = { enable = true, }, }) This is my setup and it only works in html files, no jsx or tsx files

PS Seems like adding tsx parser solved the problem for me

kristupas-g avatar Aug 06 '22 21:08 kristupas-g

@danilobjr Try adding

lvim.builtin.treesitter.autotag.enable = true 

to your config. If that doesn't work, try running :TSEnable autotag.

That worked, thanks man!

vricop avatar Oct 05 '22 07:10 vricop

I'm having the same problem. It just doesn't work. I tried in html, and tsx. Neither autotagging nor autorenaming Here is the setup I tried with. image Here is my treesitter setup. image

I'm on nvim 0.8

Gnarus-G avatar Nov 14 '22 00:11 Gnarus-G

Finally, I figured out how to make it work.

image

Content of plugins.configs.treesitter

local options = {
  auto_install = true,
  ensure_installed = {
    "lua",
    "vim",
    "go",
    "toml",
    "css",
    "tsx",
    "css",
    "html",
    "lua"
  },
  highlight = {
    enable = true,
    use_languagetree = true,
  },
  autotag = {
    enable = true,
    filetypes = {
      'html', 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'svelte', 'vue', 'tsx', 'jsx', 'rescript',
      'css', 'lua', 'xml', 'php', 'markdown'
    },
  },
  indent = { enable = true },
}

require('nvim-treesitter.configs').setup(options)

I enabled auto install lang parsers.

I am on neovim 0.8

zRich avatar Nov 15 '22 02:11 zRich

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 14 '23 11:01 stale[bot]

@danilobjr Try adding

lvim.builtin.treesitter.autotag.enable = true 

to your config. If that doesn't work, try running :TSEnable autotag.

works well with html, how could i do it with jsx?

angelollima avatar Jan 17 '23 17:01 angelollima

@danilobjr Try adding

lvim.builtin.treesitter.autotag.enable = true 

to your config. If that doesn't work, try running :TSEnable autotag.

Where do i have to put this line?

angelollima avatar Jan 20 '23 02:01 angelollima

~~Same for me. nvim-ts-autotag closes tags, but doesn't rename.~~

Update! It works!

But r or x mappings to change/delete one character don't trigger plugin!

peskovdev avatar Feb 18 '23 14:02 peskovdev

Yeah, this isn't working for me either. I followed the instructions exactly as they are in the readme and nothing happens.

s1nistr4 avatar Mar 02 '23 23:03 s1nistr4

same here even tried this but nothing for PHP and TS files

Finally, I figured out how to make it work.

image

Content of plugins.configs.treesitter

local options = {
  auto_install = true,
  ensure_installed = {
    "lua",
    "vim",
    "go",
    "toml",
    "css",
    "tsx",
    "css",
    "html",
    "lua"
  },
  highlight = {
    enable = true,
    use_languagetree = true,
  },
  autotag = {
    enable = true,
    filetypes = {
      'html', 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'svelte', 'vue', 'tsx', 'jsx', 'rescript',
      'css', 'lua', 'xml', 'php', 'markdown'
    },
  },
  indent = { enable = true },
}

require('nvim-treesitter.configs').setup(options)

I enabled auto install lang parsers.

I am on neovim 0.8

gwapocom avatar Mar 03 '23 03:03 gwapocom

it's sad, this plugin doesn't documented properly on how to install.. i need to find open ticket just to figure out on how to install it properly

nmsobri avatar Mar 14 '23 08:03 nmsobri

Many people, including myself, initially believe that simply configuring nvim-treesitter with the following code will make it work:

  autotag = {
    enable = true
  }

However, to ensure it functions correctly, you also need to install the package using your Package Manager.

In my case, using NvChad and Lazy, the configuration should be:

{
    "nvim-treesitter/nvim-treesitter",
    opts = overrides.treesitter,
  },
  {
    "windwp/nvim-ts-autotag",
    dependencies = "nvim-treesitter/nvim-treesitter",
    config = function ()
      require('nvim-ts-autotag').setup({
        -- your config
      })
    end,
    lazy = true,
    event = "VeryLazy"
  },

It would be helpful to include this information in the documentation.

hvquy001 avatar Apr 15 '23 10:04 hvquy001

For me, I have to disable alvan/vim-closetag plugin to make this plug-in work.

thenewvu avatar Apr 18 '23 09:04 thenewvu

I'm using lazy.nvim. I could make it work on HTML files. But, it didn't work on ERB(Ruby template language)

I did a :TSEnable autotag on a erb file and it wasn't able to end a p tag.

https://user-images.githubusercontent.com/97436/234002768-cff1b6bf-d6f0-4981-936c-d533411df560.mov

https://user-images.githubusercontent.com/97436/234002775-88bba0e1-9513-4949-b148-b58543c4d16e.mov

Note the different attempts by using embedded_template, erb, and eruby.

  {
    'nvim-treesitter/nvim-treesitter',
    build = function()
      require("nvim-treesitter.install").update({ with_sync = true })
    end,
    dependencies = {
      "RRethy/nvim-treesitter-endwise", -- Needed to prevent treesitter ident issue with Ruby: https://github.com/tree-sitter/tree-sitter-ruby/issues/230#issuecomment-1312403487
      'windwp/nvim-ts-autotag'
    },
    config = function()
      require'nvim-treesitter.configs'.setup {
        ensure_installed = { "ruby", "html", "embedded_template", "css", "scss", "javascript" },
        highlight = {
          disable = { "lua" },
          enable  = { "ruby", "html", "embedded_template", "eruby", "css", "scss", "javascript" }
        },
        additional_vim_regex_highlighting = false,
        endwise = {
          enable = true,
        },
        autotag = {
          enable = true,
          filetypes = { "html" , "xml", "eruby", "erb", "embedded_template" },
        }
      }
    end
  },

UPDATE: After reading this https://github.com/windwp/nvim-ts-autotag/issues/85#issuecomment-1365556082, applying the suggested patch, and changed to call the setup on nvim-ts-autotag, I got the same behavior.

acdesouza avatar Apr 24 '23 12:04 acdesouza

I'm using lazy.nvim. I could make it work on HTML files. But, it didn't work on ERB(Ruby template language)...

If my tests are correct, this PR https://github.com/windwp/nvim-ts-autotag/pull/104 fixed the issue for eruby files.

I need to config it separately, this way:

  {
    'windwp/nvim-ts-autotag',
    config = function()
      require('nvim-ts-autotag').setup({
        filetypes = { "html" , "xml", "eruby", "embedded_template" }
      })
    end
  }

https://user-images.githubusercontent.com/97436/235331284-20b79b9e-c533-4a07-9334-9deeeaecde10.mov

acdesouza avatar Apr 30 '23 01:04 acdesouza

Turn out, it missing the tsx module for treesitting for my case, make sure you have it installed by

:TSInstall tsx

tienpvse1 avatar May 19 '23 02:05 tienpvse1

The plugin only seems to work when exiting insert mode with esc, and not with ctrl-c

kleinepls avatar Jun 12 '23 15:06 kleinepls

Many people, including myself, initially believe that simply configuring nvim-treesitter with the following code will make it work:

  autotag = {
    enable = true
  }

However, to ensure it functions correctly, you also need to install the package using your Package Manager.

In my case, using NvChad and Lazy, the configuration should be:

{
    "nvim-treesitter/nvim-treesitter",
    opts = overrides.treesitter,
  },
  {
    "windwp/nvim-ts-autotag",
    dependencies = "nvim-treesitter/nvim-treesitter",
    config = function ()
      require('nvim-ts-autotag').setup({
        -- your config
      })
    end,
    lazy = true,
    event = "VeryLazy"
  },

It would be helpful to include this information in the documentation.

@hvquy001 if you would not mind, I would like to update README using your information. This will help in proper installation. I myself struggle with the installation process until found your comment. Thanks

K4R7IK avatar Jul 09 '23 18:07 K4R7IK

Many people, including myself, initially believe that simply configuring nvim-treesitter with the following code will make it work:

  autotag = {
    enable = true
  }

However, to ensure it functions correctly, you also need to install the package using your Package Manager. In my case, using NvChad and Lazy, the configuration should be:

{
    "nvim-treesitter/nvim-treesitter",
    opts = overrides.treesitter,
  },
  {
    "windwp/nvim-ts-autotag",
    dependencies = "nvim-treesitter/nvim-treesitter",
    config = function ()
      require('nvim-ts-autotag').setup({
        -- your config
      })
    end,
    lazy = true,
    event = "VeryLazy"
  },

It would be helpful to include this information in the documentation.

@hvquy001 if you would not mind, I would like to update README using your information. This will help in proper installation. I myself struggle with the installation process until found your comment. Thanks

Thank you for posting this. I got this to work immediately with lazy.nvim using this config.

exosyphon avatar Jul 16 '23 03:07 exosyphon

This worked for me as well

Something this crucial should be documented imo...

idelice avatar Sep 03 '23 22:09 idelice

Hey there!

I have autotag = { enable = true, } in my treesitter config, but it works only after I execute :TSEnable autotag after starting nvim.

How to enable it automatically?

Thanks!

Update:

I discovered that it enables automatically when I open a file from NerdTree after starting nvim in a directory, rather than directly opening a path from the command line. It's possible to live with that, but I'd love to know whether it's possible to fix. :)

dongalor avatar Sep 26 '23 00:09 dongalor

This config worked for me by throwing it in my packer.lua: use { 'windwp/nvim-ts-autotag', config = function() require('nvim-ts-autotag').setup({ filetypes = { "html", "javascript", "javascriptreact", "typescriptreact"} })

griffinbaker12 avatar Nov 13 '23 19:11 griffinbaker12

I'm facing the autotag issue in html, but it only happens when script tag is in the buffer, weird behavior.

pedroferreira37 avatar Dec 24 '23 17:12 pedroferreira37