2024-05-06 23:39:06 +08:00
|
|
|
## Selecting and manipulating text with textobjects
|
|
|
|
|
|
|
|
In Helix, textobjects are a way to select, manipulate and operate on a piece of
|
|
|
|
text in a structured way. They allow you to refer to blocks of text based on
|
|
|
|
their structure or purpose, such as a word, sentence, paragraph, or even a
|
|
|
|
function or block of code.
|
|
|
|
|
|
|
|

|
|
|
|

|
|
|
|
|
|
|
|
- `ma` - Select around the object (`va` in Vim, `<alt-a>` in Kakoune)
|
|
|
|
- `mi` - Select inside the object (`vi` in Vim, `<alt-i>` in Kakoune)
|
|
|
|
|
|
|
|
| Key after `mi` or `ma` | Textobject selected |
|
|
|
|
| --- | --- |
|
|
|
|
| `w` | Word |
|
|
|
|
| `W` | WORD |
|
|
|
|
| `p` | Paragraph |
|
2024-03-10 23:27:17 +08:00
|
|
|
| `i` | Indentation level |
|
2024-05-06 23:39:06 +08:00
|
|
|
| `(`, `[`, `'`, etc. | Specified surround pairs |
|
|
|
|
| `m` | The closest surround pair |
|
|
|
|
| `f` | Function |
|
|
|
|
| `t` | Type (or Class) |
|
|
|
|
| `a` | Argument/parameter |
|
|
|
|
| `c` | Comment |
|
|
|
|
| `T` | Test |
|
|
|
|
| `g` | Change |
|
2025-07-16 22:02:52 +08:00
|
|
|
| `x` | (X)HTML element |
|
2024-05-06 23:39:06 +08:00
|
|
|
|
|
|
|
> 💡 `f`, `t`, etc. need a tree-sitter grammar active for the current
|
|
|
|
document and a special tree-sitter query file to work properly. [Only
|
2024-06-18 16:43:36 +08:00
|
|
|
some grammars](./lang-support.md) currently have the query file implemented.
|
2024-05-06 23:39:06 +08:00
|
|
|
Contributions are welcome!
|
|
|
|
|
|
|
|
## Navigating using tree-sitter textobjects
|
|
|
|
|
|
|
|
Navigating between functions, classes, parameters, and other elements is
|
|
|
|
possible using tree-sitter and textobject queries. For
|
|
|
|
example to move to the next function use `]f`, to move to previous
|
|
|
|
type use `[t`, and so on.
|
|
|
|
|
2024-06-18 16:43:36 +08:00
|
|
|

|
2024-05-06 23:39:06 +08:00
|
|
|
|
2024-06-18 16:43:36 +08:00
|
|
|
For the full reference see the [unimpaired](./keymap.html#unimpaired) section of the key bind
|
2024-05-06 23:39:06 +08:00
|
|
|
documentation.
|
|
|
|
|
|
|
|
> 💡 This feature relies on tree-sitter textobjects
|
|
|
|
> and requires the corresponding query file to work properly.
|
|
|
|
|