nvim-ts-autotag
nvim-ts-autotag copied to clipboard
Don't work.
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.
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
Same here.
Have you ran :TSInstall html
?
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 Try adding
lvim.builtin.treesitter.autotag.enable = true
to your config. If that doesn't work, try running :TSEnable autotag
.
lvim.builtin.treesitter.autotag.enable = true
@YoungeonLee This works like a charm now. Thank you so much! 🎉
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
@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!
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.
Here is my treesitter setup.
I'm on nvim 0.8
Finally, I figured out how to make it work.
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
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.
@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?
@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?
~~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!
Yeah, this isn't working for me either. I followed the instructions exactly as they are in the readme and nothing happens.
same here even tried this but nothing for PHP and TS files
Finally, I figured out how to make it work.
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
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
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.
For me, I have to disable alvan/vim-closetag
plugin to make this plug-in work.
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.
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
Turn out, it missing the tsx module for treesitting for my case, make sure you have it installed by
:TSInstall tsx
The plugin only seems to work when exiting insert mode with esc
, and not with ctrl-c
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
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.
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. :)
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"} })
I'm facing the autotag issue in html, but it only happens when script tag is in the buffer, weird behavior.