Use the svelte5 parser for Svelte files in nvim-treesitter.
This plugin uses themixednuts/tree-sitter-htmlx under the hood and ships svelte5 queries for:
nvim-treesitter-contextnvim-treesitter-textobjectsIt supports normal Svelte filenames like Component.svelte, +page.server.svelte, and
Component.spec.svelte, and it also adds filetype detection for *.svelte.ts and *.svelte.js.
With lazy.nvim:
{
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
lazy = false,
},
{
'themixednuts/nvim-treesitter-svelte',
main = 'nvim-treesitter-svelte',
lazy = false,
dependencies = { 'nvim-treesitter/nvim-treesitter' },
opts = {
filetypes = { 'svelte' },
},
}
Install the parser:
:TSInstall svelte5
For embedded language highlighting, also install the parsers you use inside Svelte files:
:TSInstall javascript typescript css scss json regex comment
Restart Neovim after the first install, or run:
require('nvim-treesitter-svelte').load()
filetype stays sveltesvelte5nvim-treesitter-context and nvim-treesitter-textobjects work without extra query setupIf you want the parser installed without taking over Svelte buffers yet, omit filetypes from the
setup options.
require('nvim-treesitter-svelte').setup({
filetypes = { 'svelte' },
parser_name = 'svelte5',
detect_filetypes = true,
})