A Neovim plugin that provides syntax-aware text objects for selection, movement, swapping, and peeking using Tree-sitter queries.
nvim-treesitter-textobjects is a Neovim plugin that uses Tree-sitter queries to create syntax-aware text objects for editing code. It allows users to select, move, swap, and peek at code structures like functions, classes, and parameters based on the abstract syntax tree, providing more accurate and language-aware editing operations than traditional text objects.
Neovim users, particularly developers who work with multiple programming languages and want more precise, syntax-aware editing capabilities within their editor.
It leverages Tree-sitter's parsing to offer text objects that truly understand code structure, reducing errors and improving efficiency when manipulating code compared to regex-based alternatives. Its extensibility allows custom text objects for any Tree-sitter-supported language.
nvim-treesitter-textobjects is a Neovim plugin that leverages Tree-sitter's parsing capabilities to define and manipulate text objects based on the abstract syntax tree (AST) of your code. It enables precise, language-aware editing operations, moving beyond simple regex-based text objects to understand the actual structure of programming languages.
@function.inner or @class.outer) for precise selection within syntactic structures.; and , for efficient navigation.The plugin embraces Tree-sitter's accuracy to provide text objects that are deeply integrated with the language's syntax, offering a more reliable and intuitive editing experience compared to traditional pattern-based approaches.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Text objects are defined using Tree-sitter queries, enabling accurate selection of syntactic structures like inner and outer parts of functions and classes, reducing errors compared to regex-based methods.
The move module allows jumping to next or previous text objects with configurable jumps and support for multiple query groups, enhancing code navigation efficiency as shown in the keymap examples.
Supports charwise, linewise, and blockwise selection per text object via the selection_modes configuration, offering tailored editing experiences based on the query string.
Users can override or extend built-in textobjects by adding custom Tree-sitter query files, enabling support for any language with Tree-sitter grammars, as detailed in the overriding section.
Relies on Neovim's Tree-sitter support, which is marked as experimental in the README warning, requiring nightly builds or the latest stable version, leading to potential instability or breaking changes.
Requires manual setup of keymaps and configuration, including disabling built-in ftplugin mappings to avoid conflicts, which adds complexity compared to plug-and-play plugins.
Extending textobjects involves writing Tree-sitter query files with specific rules, such as avoiding special characters in query names, assuming familiarity with Tree-sitter query syntax.
Without custom keymaps defined in the setup, the plugin doesn't provide immediate functionality; users must define their own mappings or rely on community configurations.