Home Explore Blog CI



neovim

8th chunk of `runtime/doc/treesitter.txt`
f81a7627db1338659ee3cfea2df32d2e4865b639e59f0efa0000000100000fbc
 which disables spellchecking regions with `@spell`.

                                                *treesitter-highlight-conceal*
Treesitter highlighting supports |conceal| via the `conceal` and `conceal_lines`
metadata. By convention, nodes to be concealed are captured as `@conceal`, but
any capture can be used. For example, the following query can be used to hide
code block delimiters in Markdown: >query

    ((fenced_code_block_delimiter) @conceal (#set! conceal ""))
<
It is also possible to replace a node with a single character, which (unlike
legacy syntax) can be given a custom highlight. For example, the following
(ill-advised) query replaces the `!=` operator by a Unicode glyph, which is
still highlighted the same as other operators: >query

    "!=" @operator (#set! conceal "≠")
<
To conceal an entire line (do not draw it at all), a query with `conceal_lines`
metadata can be used: >query

    ((comment) @comment @spell
      (#set! conceal_lines ""))
<
Conceals specified in this way respect 'conceallevel' and 'concealcursor'.

Note that although you can use any string for `conceal`, only the first
character will be used: >query

    ; identifiers will be concealed with 'f'.
    ((identifier) @conceal (#set! conceal "foo"))
<

                                               *treesitter-highlight-priority*
Treesitter uses |nvim_buf_set_extmark()| to set highlights with a default
priority of 100. This enables plugins to set a highlighting priority lower or
higher than treesitter. It is also possible to change the priority of an
individual query pattern manually by setting its `"priority"` metadata
attribute: >query

    ((super_important_node) @superimportant (#set! priority 105))
<

                                          *treesitter-highlight-commentstring*
Treesitter highlighting supports finer-grained 'commentstring's, used by the
built-in |commenting| plugin. When the cursor is within a node that sets the
`bo.commentstring` metadata property (|treesitter-directive-set!|), that
property defines the comment delimiter (where "innermost wins"). This is
useful for languages like `JSX` that have different comment syntax depending
on the code region, for example: >query

    ((jsx_element) @_tag (#set! @_tag bo.commentstring "{/* %s */}"))
<
When multiple captures set this metadata over a region, only the innermost
(most specific) one is applied to a given area.

==============================================================================
TREESITTER LANGUAGE INJECTIONS                *treesitter-language-injections*
<

Note the following information is adapted from:
  https://tree-sitter.github.io/tree-sitter/syntax-highlighting#language-injection

Some source files contain code written in multiple different languages.
Examples include:

    • HTML files, which can contain JavaScript inside of `<script>` tags and
      CSS inside of `<style>` tags
    • ERB files, which contain Ruby inside of `<%` `%>` tags, and HTML outside of
      those tags
    • PHP files, which can contain HTML between the `<php` tags
    • JavaScript files, which contain regular expression syntax within regex
      literals
    • Ruby, which can contain snippets of code inside of heredoc literals,
      where the heredoc delimiter often indicates the language
    • Lua, which can contain snippets of Vimscript inside |vim.cmd()| calls.
    • Vimscript, which can contain snippets of Lua inside |:lua-heredoc|
      blocks.

All of these examples can be modeled in terms of a parent syntax tree and one
or more injected syntax trees, which reside inside of certain nodes in the
parent tree. The language injection query allows you to specify these
“injections” using the following captures:

    • `@injection.content` - indicates that the captured node should have its
      contents re-parsed using another language. If there are multiple
      `@injection.content` captures in one pattern, all ranges will be
      collected and parsed as one tree. This allows

Title: Nvim Treesitter Highlighting: Conceal, Priority, Comment Strings, and Language Injections
Summary
This section explains how to use conceal metadata to hide or replace nodes in Treesitter highlighting, including character replacements and line concealment. It also covers setting highlight priority to override default Treesitter settings and customizing comment strings for languages like JSX with varying comment syntax. Finally, it introduces language injections, allowing code in different languages within a single file (like HTML with JavaScript) to be parsed and highlighted correctly using captures like `@injection.content`.