Skip to content

Manually highlighting a region of a buffer using an explicit treesitter parser #27940

Answered by justinmk
chipsenkbeil asked this question in Q&A
Discussion options

You must be logged in to vote

In general to highlight a range of text the main function ins nvim_buf_set_extmark(). But I'm not sure how to combine that with a treesitter parser.

:help vim.treesitter.get_string_parser() seems related, but I think it's not bound to a buffer.

For custom highlighting start with :help :EditQuery https://neovim.io/doc/user/treesitter.html#vim.treesitter.query.edit() , you could define a query that enables highlighting only for a certain section of a document. However, doing that dynamically might be weird.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@chipsenkbeil
Comment options

@chipsenkbeil
Comment options

Answer selected by chipsenkbeil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants