Skip to content

Highlighting in NeoVim

Alex LaFroscia edited this page Feb 28, 2021 · 2 revisions

This should cover how to use this package to highlight Handlebars files in NeoVim through their nvim-treesitter project.

Prerequisites

  1. nvim-treesitter installed as a plugin to your NeoVim installation
  2. The tree-sitter-glimmer repository cloned to your computer

Configure nvim-treesitter

You can configure nvim-treesitter with an additional grammar like so. Note that the following is Lua code; you can use Lua inside a VimScript file as shown here.

local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.glimmer = {
  install_info = {
    url = "~/Code/tree-sitter-glimmer",
    files = {
      "src/parser.c",
      "src/scanner.c"
    }
  },
  filetype = "hbs",
  used_by = {
    "handlebars",
    "html.handlebars"
  }
}

Note that the url should be a path to wherever you have the repository cloned to your computer.

Configuring Highlighting

nvim-treesitter does not automatically discover highlighting configurations that are part of a manually-installed installed grammar.

The easiest option I've found is to create a queries/glimmer directory inside your main NeoVim configuration folder (the location of your init.vim) and then create a symlink from there to the highlights.scm file in this repository

mkdir -p $DOTFILES/nvim/queries/glimmer
ln -s ~/Code/tree-sitter-glimmer/queries/highlights.scm $DOTFILES/nvim/queries/glimmer/

Tips and Tricks

  • Run :TSUpdate glimmer after pulling any new changes to the grammar to ensure nvim-treesitter includes the latest changes