Debian Codegraph @

book/src/textobjects.md

raw symbols SCIP
1 ## Selecting and manipulating text with textobjects
2
3 In Helix, textobjects are a way to select, manipulate and operate on a piece of
4 text in a structured way. They allow you to refer to blocks of text based on
5 their structure or purpose, such as a word, sentence, paragraph, or even a
6 function or block of code.
7
8 ![Textobject demo](https://user-images.githubusercontent.com/23398472/124231131-81a4bb00-db2d-11eb-9d10-8e577ca7b177.gif)
9 ![Textobject tree-sitter demo](https://user-images.githubusercontent.com/23398472/132537398-2a2e0a54-582b-44ab-a77f-eb818942203d.gif)
10
11 - `ma` - Select around the object (`va` in Vim, `<alt-a>` in Kakoune)
12 - `mi` - Select inside the object (`vi` in Vim, `<alt-i>` in Kakoune)
13
14 | Key after `mi` or `ma` | Textobject selected |
15 | --- | --- |
16 | `w` | Word |
17 | `W` | WORD |
18 | `p` | Paragraph |
19 | `(`, `[`, `'`, etc. | Specified surround pairs |
20 | `m` | The closest surround pair |
21 | `f` | Function |
22 | `t` | Type (or Class) |
23 | `a` | Argument/parameter |
24 | `c` | Comment |
25 | `T` | Test |
26 | `g` | Change |
27 | `x` | (X)HTML element |
28
29 > 💡 `f`, `t`, etc. need a tree-sitter grammar active for the current
30 document and a special tree-sitter query file to work properly. [Only
31 some grammars](./lang-support.md) currently have the query file implemented.
32 Contributions are welcome!
33
34 ## Navigating using tree-sitter textobjects
35
36 Navigating between functions, classes, parameters, and other elements is
37 possible using tree-sitter and textobject queries. For
38 example to move to the next function use `]f`, to move to previous
39 type use `[t`, and so on.
40
41 ![Tree-sitter-nav-demo](https://user-images.githubusercontent.com/23398472/152332550-7dfff043-36a2-4aec-b8f2-77c13eb56d6f.gif)
42
43 For the full reference see the [unimpaired](./keymap.md#unimpaired) section of the key bind
44 documentation.
45
46 > 💡 This feature relies on tree-sitter textobjects
47 > and requires the corresponding query file to work properly.
48