generated from nvim-treesitter/module-template
-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathnvim-treesitter-textobjects.txt
161 lines (143 loc) · 4.73 KB
/
nvim-treesitter-textobjects.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
*nvim-treesitter-textobjects* Syntax aware |text-objects|, select, move, swap, and peek support.
Type |gO| to see the table of contents.
==============================================================================
MODULES *nvim-treesitter-textobjects-modules*
Available modules for |nvim-treesitter|.
------------------------------------------------------------------------------
*nvim-treesitter-text-objects-select-submod*
Text object selection~
Define your own text objects mappings
similar to `ip` (inner paragraph) and `ap` (a paragraph).
Query files: `textobjects.scm`.
Supported options:
- enable: `true` or `false`.
- disable: list of languages.
- lookahead: `true` or `false`, whether or not to look ahead for the textobject
- keymaps: map of keymaps to a tree-sitter query
(`(function_definition) @function`) or capture group (`@function.inner`).
>
lua <<EOF
require'nvim-treesitter.configs'.setup {
textobjects = {
select = {
enable = true,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
["ic"] = "@class.inner",
-- Or you can define your own textobjects like this
["iF"] = {
python = "(function_definition) @function",
cpp = "(function_definition) @function",
c = "(function_definition) @function",
java = "(method_declaration) @function",
},
},
},
},
}
EOF
<
------------------------------------------------------------------------------
*nvim-treesitter-text-objects-swap-submod*
Swap text objects~
Define your own mappings to swap the node under the cursor with the next or previous one,
like function parameters or arguments.
Query files: `textobjects.scm`.
Supported options:
- enable: `true` or `false`.
- disable: list of languages.
- swap_next: map of keymaps to a tree-sitter capture group (`@parameter.inner`).
- swap_previous: same as swap_next.
>
lua <<EOF
require'nvim-treesitter.configs'.setup {
textobjects = {
swap = {
enable = true,
swap_next = {
["<leader>a"] = "@parameter.inner",
},
swap_previous = {
["<leader>A"] = "@parameter.inner",
},
},
},
}
EOF
<
------------------------------------------------------------------------------
*nvim-treesitter-text-objects-move-submod*
Go to next/previous text object~
Define your own mappings to jump to the next or previous text object.
This is similar to |]m|, |[m|, |]M|, |[M| Neovim's mappings to jump to the next
or previous function.
Query files: `textobjects.scm`.
Supported options:
- enable: `true` or `false`.
- disable: list of languages.
- set_jumps: whether to set jumps in the jumplist
- goto_next_start: map of keymaps to a tree-sitter capture group (`@function.outer`).
- goto_next_end: same as goto_next_start, but it jumps to the start of
the text object.
- goto_previous_start: same as goto_next_start, but it jumps to the previous
text object.
- goto_previous_end: same as goto_next_end, but it jumps to the previous
text object.
>
lua <<EOF
require'nvim-treesitter.configs'.setup {
textobjects = {
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
["]m"] = "@function.outer",
["]]"] = "@class.outer",
},
goto_next_end = {
["]M"] = "@function.outer",
["]["] = "@class.outer",
},
goto_previous_start = {
["[m"] = "@function.outer",
["[["] = "@class.outer",
},
goto_previous_end = {
["[M"] = "@function.outer",
["[]"] = "@class.outer",
},
},
},
}
EOF
<
------------------------------------------------------------------------------
*nvim-treesitter-textobjects-lsp_interop-submod*
LSP interop~
- peek_definition_code: show textobject surrounding definition as determined
using Neovim's built-in LSP in a floating window. Press the shortcut twice
to enter the floating window (when https://github.com/neovim/neovim/pull/12720
or its successor is merged)
Supported options:
- enable: `true` or `false`.
- border: 'none' (default), 'single', 'double', 'rounded', 'solid', 'shadow'.
>
lua <<EOF
require'nvim-treesitter.configs'.setup {
textobjects = {
lsp_interop = {
enable = true,
border = "none",
peek_definition_code = {
["<leader>df"] = "@function.outer",
["<leader>dF"] = "@class.outer",
},
},
},
}
EOF
<
vim:tw=78:ts=8:expandtab:noet:ft=help:norl: