Skip to content

Instantly share code, notes, and snippets.

@gnull
Created January 8, 2025 17:42
Show Gist options
  • Save gnull/151a18bc840eeb282286b5a59bb400b6 to your computer and use it in GitHub Desktop.
Save gnull/151a18bc840eeb282286b5a59bb400b6 to your computer and use it in GitHub Desktop.
Tree sitter highlinting for kakoune, a minimal example
I tried setting up tree-sitter with kakoune,
and it turned out to be not quite trivial.
There are multiple plugins that aim to provide this functionality
of varying degree of completeness.
I felt that existing documentation for them focuses low-level details,
and there isn't a simple list of steps to get something working.
Below are such steps to get a minimal working syntax highlighting for Kakoune using tree-sitter.
I use use `latex` language as an example, put your languages in its place.
1. Install <https://git.sr.ht/~hadronized/kak-tree-sitter>.
Either by compiling from source, or using your package manager.
It comes with two executables, `ktsctl` and `kak-tree-sitter`.
2. Copy [default config](https://git.sr.ht/~hadronized/kak-tree-sitter/tree/66f06175f2198965bc53e9f4418cb9abc8e1be04/item/kak-tree-sitter-config/default-config.toml)
to `~/.config/kak-tree-sitter/config.toml`.
You may want to add something like this so kak-tree-sitter overrides the default highligher:
```toml
[language.latex]
remove_default_highlighter = true
```
3. Symlink [night-owl.kak](https://git.sr.ht/~hadronized/kakoune-tree-sitter-themes/tree/6997b1902f36964944d400aefa19ad9ca132f0b5/item/colors/nightowl/night-owl.kak)
to `~/.config/kak/colors/night-owl.kak`.
Check the linked repo for more themes.
4. Run `ktsctl sync latex`.
This will install the parsers and queries declared in `config.toml`.
5. Add the following to your `~/.config/kak/kakrc`.
```kak
eval %sh{ kak-tree-sitter -dksvv --init "${kak_session}" }
colorscheme night-owl
```
6. Tree-sitter highlighting is enabled.
Check the documentation of <https://git.sr.ht/~hadronized/kak-tree-sitter> to learn how to customize the above steps.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment