Create your own pair objects using tree-sitter queries!
You can install nvim-treesitter-pairs with your favorite package manager, or using the default pack feature of Neovim!
If you are using vim-plug, put this in your init.vim file:
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'theHamsta/nvim-treesitter-pairs'
Pairs are configured via queries/<language>/pairs.scm
query files.
lua <<EOF
require'nvim-treesitter.configs'.setup {
pairs = {
enable = true,
disable = {},
highlight_pair_events = {}, -- e.g. {"CursorMoved"}, -- when to highlight the pairs, use {} to deactivate highlighting
highlight_self = false, -- whether to highlight also the part of the pair under cursor (or only the partner)
goto_right_end = false, -- whether to go to the end of the right partner or the beginning
fallback_cmd_normal = "call matchit#Match_wrapper('',1,'n')", -- What command to issue when we can't find a pair (e.g. "normal! %")
keymaps = {
goto_partner = "<leader>%",
delete_balanced = "X",
},
delete_balanced = {
only_on_first_char = false, -- whether to trigger balanced delete when on first character of a pair
fallback_cmd_normal = nil, -- fallback command when no pair found, can be nil
longest_partner = false, -- whether to delete the longest or the shortest pair when multiple found.
-- E.g. whether to delete the angle bracket or whole tag in <pair> </pair>
}
}
},
EOF
We hope we can fix them soon!
- Can only cycle through 2-element pairs
- Only works in normal mode
- Queries are not complete at the moment
- Does not support counts
- Support all things that matchit does
- Is tree-sitter really needed or should we just use mature vim plugins that use regexes?
Alternatives: https://github.com/andymass/vim-matchup added tree-sitter support for some languages. Thy can be configured via matchup.scm
.
astro | |
bash | 👍 |
beancount | |
bibtex | |
c | 👍 |
c_sharp | 👍 |
clojure | 👍 |
cmake | |
comment | |
commonlisp | 👍 |
cooklang | |
cpp | 👍 |
css | 👍 |
cuda | |
d | |
dart | 👍 |
devicetree | |
dockerfile | |
dot | |
eex | |
elixir | |
elm | 👍 |
elvish | |
erlang | |
fennel | 👍 |
fish | |
foam | |
fortran | |
fusion | |
Godot (gdscript) | |
gleam | |
Glimmer and Ember | |
glsl | |
go | 👍 |
Godot Resources (gdresource) | |
gomod | |
gowork | |
graphql | 👍 |
hack | |
haskell | 👍 |
hcl | |
heex | |
help | |
hjson | |
hocon | |
html | 👍 |
http | |
java | 👍 |
javascript | 👍 |
jsdoc | |
json | 👍 |
json5 | |
JSON with comments | |
julia | 👍 |
kotlin | |
lalrpop | |
latex | 👍 |
ledger | |
llvm | |
lua | 👍 |
make | |
markdown | |
ninja | |
nix | 👍 |
norg | |
ocaml | |
ocaml_interface | |
ocamllex | 👍 |
pascal | |
perl | |
php | 👍 |
phpdoc | |
pioasm | |
prisma | |
pug | |
python | 👍 |
ql | |
Tree-sitter query language | |
r | |
rasi | |
regex | |
rego | |
rst | |
ruby | |
rust | 👍 |
scala | |
scheme | |
scss | 👍 |
slint | |
solidity | |
sparql | |
supercollider | |
surface | |
svelte | 👍 |
swift | |
teal | |
tlaplus | |
todotxt | |
toml | 👍 |
tsx | |
turtle | |
typescript | 👍 |
vala | |
verilog | |
vim | |
vue | 👍 |
wgsl | |
yaml | |
yang | |
zig |