#33346·neovim

Treesitter-aware search

Author: clasonCreated Apr 6, 2025Updated Sep 30, 2026
Labelstreesitterop-textobjects

Problem

No way to structurally restrict the scope of searching (and replacing/acting) with :s and friends.

Expected behavior

Allow scoping :s with treesitter captures, e.g.,

vim
:s/foo/bar/@comment

to only search and replace inside comment captures. Should respect the usual fallback (e.g., also replace in @comment.documentation).

Stretch goal: search outside a capture with :s/.../.../!@comment.

See https://github.com/vigoux/architext.nvim (which allows specifying arbitrary tree-sitter queries, but highlight captures seem like a sweet spot for power vs. usability).