[nvim][tree-sitter] : Enable syntax highlighting on .hbs(handelbars) files

495 views Asked by At

I'm using neovim and tree-sitter for syntac highlighting in files. But on *.hbs (handelbars) file. Syntax highlighting not working. HTML & HBS Shares same syntax. How can i get syntax highlighting on hbs files?

I tried to enable syntax highlighting via ChatGPT. These are the commands i have tried

require('nvim-treesitter.configs).setup({
  -- Other Configurations
  languages = {
    html = { "html", "hbs" }
}
})

Then i tred this in init.vim file

" For HTML
au BufRead,BufNewFile *.html setlocal filetype=html

" For Handlebars
au BufRead,BufNewFile *.hbs setlocal filetype=handlebars

But nothing works. On hbs file

2

There are 2 answers

0
OlivierLarue On

init.vim:

au BufRead,BufNewFile *.hbs set filetype=html

Or init.lua:

vim.cmd('autocmd BufRead,BufNewFile *.hbs set filetype=html')
0
leonard georg On

If anyone stumbles upon this, one can assign filetypes to treesitter parsers according to the documentation as follows:

vim.treesitter.language.register("<tree-sitter>", "<filetype>")
vim.treesitter.language.register("html", "aspx")

this means that the "html" parser will be used for files of the type "aspx"