2020-10-19 11:42:47 +02:00
|
|
|
# nvim-treesitter-context
|
|
|
|
|
2021-04-03 07:56:37 +02:00
|
|
|
Lightweight alternative to [context.vim](https://github.com/wellle/context.vim)
|
2020-10-19 11:42:47 +02:00
|
|
|
|
2022-04-17 14:05:54 +02:00
|
|
|
## Requirements
|
|
|
|
|
2023-10-05 00:37:46 +02:00
|
|
|
Neovim >= v0.9.0
|
2022-04-17 14:05:54 +02:00
|
|
|
|
|
|
|
Note: if you need support for Neovim 0.6.x please use the tag `compat/0.6`.
|
|
|
|
|
2020-10-19 11:42:47 +02:00
|
|
|
## Screenshot
|
|
|
|
|
2020-10-19 11:45:48 +02:00
|
|
|
![theme](./static/demo.gif)
|
2020-10-19 11:42:47 +02:00
|
|
|
|
2023-05-11 11:41:37 +02:00
|
|
|
## Supported Languages
|
2024-06-27 16:53:25 +02:00
|
|
|
|
|
|
|
Note: support for specific languages is strictly community maintained and can break from time to time as parsers are updated.
|
|
|
|
|
2023-05-11 11:41:37 +02:00
|
|
|
<details>
|
|
|
|
<summary>click to expand</summary
|
2020-10-19 11:42:47 +02:00
|
|
|
|
2024-01-08 11:44:31 +01:00
|
|
|
- [x] `apex`
|
2023-03-08 14:17:20 +01:00
|
|
|
- [x] `bash`
|
|
|
|
- [x] `c`
|
2023-04-04 18:31:27 +02:00
|
|
|
- [x] `c_sharp`
|
2023-05-07 11:11:20 +02:00
|
|
|
- [x] `capnp`
|
2023-10-10 08:11:10 +02:00
|
|
|
- [x] `clojure`
|
2023-08-18 11:28:43 +02:00
|
|
|
- [x] `cmake`
|
2023-03-08 14:17:20 +01:00
|
|
|
- [x] `cpp`
|
2023-04-28 17:24:21 +02:00
|
|
|
- [x] `css`
|
2023-05-08 04:48:45 +02:00
|
|
|
- [x] `cuda`
|
2023-11-17 18:00:00 +01:00
|
|
|
- [x] `cue`
|
2023-05-24 15:32:16 +02:00
|
|
|
- [x] `d`
|
2023-03-24 17:32:33 +01:00
|
|
|
- [x] `dart`
|
2024-08-06 23:21:48 +02:00
|
|
|
- [x] `devicetree`
|
2023-03-13 15:04:53 +01:00
|
|
|
- [x] `elixir`
|
2024-05-15 14:54:34 +02:00
|
|
|
- [x] `elm`
|
2023-11-17 18:00:00 +01:00
|
|
|
- [x] `fennel`
|
2023-11-21 10:33:31 +01:00
|
|
|
- [x] `fish`
|
2023-05-11 14:45:20 +02:00
|
|
|
- [x] `fortran`
|
2024-03-20 23:22:57 +01:00
|
|
|
- [x] `gdscript`
|
2023-06-13 18:15:54 +02:00
|
|
|
- [x] `glimmer`
|
2023-03-13 15:04:53 +01:00
|
|
|
- [x] `go`
|
2023-04-29 21:12:35 +02:00
|
|
|
- [x] `graphql`
|
2024-02-16 11:53:55 +01:00
|
|
|
- [x] `groovy`
|
2023-06-17 18:58:56 +02:00
|
|
|
- [x] `haskell`
|
2023-05-06 23:23:32 +02:00
|
|
|
- [x] `html_tags`
|
2023-04-28 17:24:21 +02:00
|
|
|
- [x] `ini`
|
2023-10-09 19:54:25 +02:00
|
|
|
- [x] `janet` (using the "janet_simple" grammar)
|
2023-03-13 15:04:53 +01:00
|
|
|
- [x] `java`
|
|
|
|
- [x] `javascript`
|
2023-03-08 14:17:20 +01:00
|
|
|
- [x] `json`
|
2023-09-30 19:00:00 +02:00
|
|
|
- [x] `jsonnet`
|
2023-09-26 17:06:56 +02:00
|
|
|
- [x] `julia`
|
2023-03-13 15:04:53 +01:00
|
|
|
- [x] `latex`
|
2023-10-04 02:10:53 +02:00
|
|
|
- [x] `liquidsoap`
|
2023-11-21 10:33:31 +01:00
|
|
|
- [x] `lua`
|
2023-03-08 14:17:20 +01:00
|
|
|
- [x] `markdown`
|
2023-05-01 17:12:21 +02:00
|
|
|
- [x] `matlab`
|
2023-09-23 20:39:16 +02:00
|
|
|
- [x] `nim`
|
2023-06-02 03:02:08 +02:00
|
|
|
- [x] `nix`
|
2023-05-11 14:45:20 +02:00
|
|
|
- [x] `norg`
|
2023-11-17 18:00:00 +01:00
|
|
|
- [x] `objdump`
|
2023-04-28 17:24:21 +02:00
|
|
|
- [x] `ocaml_interface`
|
|
|
|
- [x] `ocaml`
|
2023-08-20 00:49:10 +02:00
|
|
|
- [x] `odin`
|
2023-03-08 14:17:20 +01:00
|
|
|
- [x] `php`
|
2024-02-10 15:35:05 +01:00
|
|
|
- [x] `php_only`
|
2023-04-29 20:20:06 +02:00
|
|
|
- [x] `prisma`
|
2024-07-04 14:44:25 +02:00
|
|
|
- [x] `proto`
|
2023-03-13 15:04:53 +01:00
|
|
|
- [x] `python`
|
2023-03-20 01:38:48 +01:00
|
|
|
- [x] `r`
|
2024-04-13 16:58:37 +02:00
|
|
|
- [x] `ruby` (and `rspec`)
|
2023-03-13 15:04:53 +01:00
|
|
|
- [x] `rust`
|
2023-03-08 14:17:20 +01:00
|
|
|
- [x] `scala`
|
2023-04-28 17:24:21 +02:00
|
|
|
- [x] `scss`
|
2023-05-07 01:05:39 +02:00
|
|
|
- [x] `smali`
|
2023-11-21 10:33:31 +01:00
|
|
|
- [x] `solidity`
|
2024-02-19 01:42:42 +01:00
|
|
|
- [x] `svelte`
|
2023-04-28 17:24:21 +02:00
|
|
|
- [x] `swift`
|
2024-05-02 16:05:30 +02:00
|
|
|
- [x] `tact`
|
2023-09-01 15:12:18 +02:00
|
|
|
- [x] `tcl`
|
2023-03-08 14:17:20 +01:00
|
|
|
- [x] `teal`
|
2023-11-17 18:00:00 +01:00
|
|
|
- [x] `templ`
|
2023-03-08 15:24:54 +01:00
|
|
|
- [x] `terraform`
|
2023-03-08 14:17:20 +01:00
|
|
|
- [x] `toml`
|
2023-03-11 12:13:10 +01:00
|
|
|
- [x] `tsx`
|
2023-03-13 15:04:53 +01:00
|
|
|
- [x] `typescript`
|
2023-10-27 12:43:51 +02:00
|
|
|
- [x] `typoscript`
|
2023-05-16 09:13:56 +02:00
|
|
|
- [x] `usd`
|
2023-03-13 15:04:53 +01:00
|
|
|
- [x] `verilog`
|
2023-03-08 14:17:20 +01:00
|
|
|
- [x] `vim`
|
2024-02-20 02:08:33 +01:00
|
|
|
- [x] `vue`
|
2023-11-21 10:33:31 +01:00
|
|
|
- [x] `xml`
|
2023-03-13 15:04:53 +01:00
|
|
|
- [x] `yaml`
|
2023-11-21 10:33:31 +01:00
|
|
|
- [x] `yang`
|
2023-04-28 17:24:21 +02:00
|
|
|
- [x] `zig`
|
2024-09-14 17:42:31 +02:00
|
|
|
- [x] `ada`
|
2023-03-08 14:17:20 +01:00
|
|
|
- [ ] `agda`
|
|
|
|
- [ ] `arduino`
|
|
|
|
- [ ] `astro`
|
|
|
|
- [ ] `beancount`
|
|
|
|
- [ ] `bibtex`
|
|
|
|
- [ ] `bicep`
|
|
|
|
- [ ] `blueprint`
|
|
|
|
- [ ] `chatito`
|
|
|
|
- [ ] `clojure`
|
|
|
|
- [ ] `commonlisp`
|
|
|
|
- [ ] `cooklang`
|
|
|
|
- [ ] `cpon`
|
|
|
|
- [ ] `dhall`
|
|
|
|
- [ ] `dockerfile`
|
|
|
|
- [ ] `dot`
|
|
|
|
- [ ] `ebnf`
|
|
|
|
- [ ] `ecma`
|
|
|
|
- [ ] `eex`
|
|
|
|
- [ ] `elsa`
|
|
|
|
- [ ] `elvish`
|
|
|
|
- [ ] `embedded_template`
|
|
|
|
- [ ] `erlang`
|
|
|
|
- [ ] `fennel`
|
|
|
|
- [ ] `foam`
|
|
|
|
- [ ] `fsh`
|
|
|
|
- [ ] `func`
|
|
|
|
- [ ] `fusion`
|
|
|
|
- [ ] `gdscript`
|
|
|
|
- [ ] `git_rebase`
|
|
|
|
- [ ] `gleam`
|
|
|
|
- [ ] `glsl`
|
|
|
|
- [ ] `godot_resource`
|
|
|
|
- [ ] `gomod`
|
|
|
|
- [ ] `gosum`
|
|
|
|
- [ ] `gowork`
|
|
|
|
- [ ] `hack`
|
|
|
|
- [ ] `hcl`
|
|
|
|
- [ ] `heex`
|
|
|
|
- [ ] `hjson`
|
|
|
|
- [ ] `hlsl`
|
|
|
|
- [ ] `hocon`
|
|
|
|
- [ ] `html`
|
|
|
|
- [ ] `htmldjango`
|
|
|
|
- [ ] `http`
|
|
|
|
- [ ] `jq`
|
|
|
|
- [ ] `jsdoc`
|
|
|
|
- [ ] `json5`
|
|
|
|
- [ ] `jsonc`
|
|
|
|
- [ ] `jsx`
|
|
|
|
- [ ] `kdl`
|
|
|
|
- [ ] `kotlin`
|
|
|
|
- [ ] `lalrpop`
|
|
|
|
- [ ] `ledger`
|
|
|
|
- [ ] `llvm`
|
|
|
|
- [ ] `m68k`
|
2024-02-19 01:05:13 +01:00
|
|
|
- [ ] `markdown_inline`
|
2023-03-08 14:17:20 +01:00
|
|
|
- [ ] `menhir`
|
|
|
|
- [ ] `mermaid`
|
|
|
|
- [ ] `meson`
|
|
|
|
- [ ] `nickel`
|
|
|
|
- [ ] `ocamllex`
|
|
|
|
- [ ] `pascal`
|
|
|
|
- [ ] `perl`
|
|
|
|
- [ ] `phpdoc`
|
|
|
|
- [ ] `pioasm`
|
|
|
|
- [ ] `po`
|
|
|
|
- [ ] `poe_filter`
|
|
|
|
- [ ] `prql`
|
|
|
|
- [ ] `pug`
|
|
|
|
- [ ] `ql`
|
|
|
|
- [ ] `qmldir`
|
|
|
|
- [ ] `qmljs`
|
|
|
|
- [ ] `query`
|
|
|
|
- [ ] `racket`
|
|
|
|
- [ ] `rasi`
|
|
|
|
- [ ] `rego`
|
|
|
|
- [ ] `rnoweb`
|
|
|
|
- [ ] `ron`
|
|
|
|
- [ ] `rst`
|
|
|
|
- [ ] `scheme`
|
|
|
|
- [ ] `slint`
|
|
|
|
- [ ] `smithy`
|
|
|
|
- [ ] `sparql`
|
|
|
|
- [ ] `sql`
|
|
|
|
- [ ] `starlark`
|
|
|
|
- [ ] `supercollider`
|
|
|
|
- [ ] `surface`
|
|
|
|
- [ ] `sxhkdrc`
|
|
|
|
- [ ] `t32`
|
|
|
|
- [ ] `thrift`
|
|
|
|
- [ ] `tiger`
|
|
|
|
- [ ] `tlaplus`
|
|
|
|
- [ ] `todotxt`
|
|
|
|
- [ ] `turtle`
|
|
|
|
- [ ] `twig`
|
|
|
|
- [ ] `ungrammar`
|
|
|
|
- [ ] `v`
|
|
|
|
- [ ] `vala`
|
|
|
|
- [ ] `vhs`
|
|
|
|
- [ ] `wgsl`
|
|
|
|
- [ ] `wgsl_bevy`
|
|
|
|
- [ ] `yuck`
|
2023-05-12 12:01:51 +02:00
|
|
|
|
2023-05-11 11:42:18 +02:00
|
|
|
</details>
|
2023-05-12 12:01:51 +02:00
|
|
|
|
2021-05-24 18:37:40 +02:00
|
|
|
## Configuration
|
|
|
|
|
|
|
|
(Default values are shown below)
|
|
|
|
|
2023-08-26 10:23:15 +02:00
|
|
|
Note: calling `setup()` is optional.
|
|
|
|
|
2021-05-24 18:37:40 +02:00
|
|
|
```lua
|
2021-08-01 04:07:27 +02:00
|
|
|
require'treesitter-context'.setup{
|
2023-03-08 14:17:20 +01:00
|
|
|
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
|
|
|
|
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
|
|
|
|
min_window_height = 0, -- Minimum editor window height to enable context. Values <= 0 mean no limit.
|
|
|
|
line_numbers = true,
|
2023-08-26 10:23:15 +02:00
|
|
|
multiline_threshold = 20, -- Maximum number of lines to show for a single context
|
2023-03-08 14:17:20 +01:00
|
|
|
trim_scope = 'outer', -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
|
|
|
|
mode = 'cursor', -- Line used to calculate context. Choices: 'cursor', 'topline'
|
|
|
|
-- Separator between context and content. Should be a single character string, like '-'.
|
|
|
|
-- When separator is set, the context will only show up when there are at least 2 lines above cursorline.
|
|
|
|
separator = nil,
|
|
|
|
zindex = 20, -- The Z-index of the context window
|
2023-05-11 11:03:14 +02:00
|
|
|
on_attach = nil, -- (fun(buf: integer): boolean) return false to disable attaching
|
2021-05-24 18:37:40 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-10-19 11:42:47 +02:00
|
|
|
## Commands
|
|
|
|
|
2021-05-14 00:17:20 +02:00
|
|
|
`TSContextEnable`, `TSContextDisable` and `TSContextToggle`.
|
2020-10-19 11:42:47 +02:00
|
|
|
|
2021-02-11 16:09:36 +01:00
|
|
|
## Appearance
|
|
|
|
|
|
|
|
Use the highlight group `TreesitterContext` to change the colors of the
|
|
|
|
context. Per default it links to `NormalFloat`.
|
2022-03-23 11:57:24 +01:00
|
|
|
|
|
|
|
Use the highlight group `TreesitterContextLineNumber` to change the colors of the
|
|
|
|
context line numbers if `line_numbers` is set. Per default it links to `LineNr`.
|
2022-10-23 18:58:21 +02:00
|
|
|
|
2023-06-05 14:42:28 +02:00
|
|
|
Use the highlight group `TreesitterContextSeparator` to change the colors of the
|
|
|
|
separator if `separator` is set. By default it links to `FloatBorder`.
|
|
|
|
|
2024-01-25 18:44:47 +01:00
|
|
|
Use the highlight groups `TreesitterContextBottom` and/or
|
|
|
|
`TreesitterContextLineNumberBottom` to change the highlight of the last line of
|
|
|
|
the context window. By default it links to `NONE`.
|
|
|
|
However, you can use this to create a border by applying an underline highlight, e.g,
|
|
|
|
for an underline across the screen:
|
2022-11-09 00:40:20 +01:00
|
|
|
|
2022-10-23 18:58:21 +02:00
|
|
|
```vim
|
|
|
|
hi TreesitterContextBottom gui=underline guisp=Grey
|
2024-01-25 18:44:47 +01:00
|
|
|
hi TreesitterContextLineNumberBottom gui=underline guisp=Grey
|
|
|
|
```
|
|
|
|
|
|
|
|
Or an underline below the line numbers only:
|
|
|
|
|
|
|
|
```vim
|
|
|
|
hi TreesitterContextLineNumberBottom gui=underline guisp=Grey
|
2022-10-23 18:58:21 +02:00
|
|
|
```
|
2023-03-08 14:17:20 +01:00
|
|
|
|
2023-05-11 13:10:09 +02:00
|
|
|
## Jumping to context (upwards)
|
|
|
|
|
|
|
|
```lua
|
|
|
|
vim.keymap.set("n", "[c", function()
|
2023-12-23 11:16:06 +01:00
|
|
|
require("treesitter-context").go_to_context(vim.v.count1)
|
2023-05-11 13:10:09 +02:00
|
|
|
end, { silent = true })
|
|
|
|
```
|
|
|
|
|
2023-03-08 14:17:20 +01:00
|
|
|
## Adding support for other languages
|
|
|
|
|
2023-05-11 11:50:42 +02:00
|
|
|
See [CONTRIBUTING.md](CONTRIBUTING.md)
|