@@ -5,6 +5,11 @@ local map_cmd = bind.map_cmd
55local map_callback = bind .map_callback
66local et = bind .escape_termcode
77
8+ local ts_to_select = require (" nvim-treesitter-textobjects.select" )
9+ local ts_to_swap = require (" nvim-treesitter-textobjects.swap" )
10+ local ts_to_move = require (" nvim-treesitter-textobjects.move" )
11+ local ts_to_repeat_move = require (" nvim-treesitter-textobjects.repeatable_move" )
12+
813local mappings = {
914 builtins = {
1015 -- Builtins: Save & Quit
@@ -133,6 +138,102 @@ local mappings = {
133138
134139 -- Plugin: suda.vim
135140 [" n|<A-s>" ] = map_cu (" SudaWrite" ):with_silent ():with_noremap ():with_desc (" editn: Save file using sudo" ),
141+
142+ -- Plugin: nvim-treesitter-textobjects
143+ -- Text objects: select
144+ [" xo|af" ] = map_callback (function ()
145+ ts_to_select .select_textobject (" @function.outer" , " textobjects" )
146+ end )
147+ :with_silent ()
148+ :with_noremap ()
149+ :with_desc (" editxo: Select function.outer" ),
150+ [" xo|if" ] = map_callback (function ()
151+ ts_to_select .select_textobject (" @function.inner" , " textobjects" )
152+ end )
153+ :with_silent ()
154+ :with_noremap ()
155+ :with_desc (" editxo: Select function.inner" ),
156+ [" xo|ac" ] = map_callback (function ()
157+ ts_to_select .select_textobject (" @class.outer" , " textobjects" )
158+ end )
159+ :with_silent ()
160+ :with_noremap ()
161+ :with_desc (" editxo: Select class.outer" ),
162+ [" xo|ic" ] = map_callback (function ()
163+ ts_to_select .select_textobject (" @class.inner" , " textobjects" )
164+ end )
165+ :with_silent ()
166+ :with_noremap ()
167+ :with_desc (" editoxo: Select class.inner" ),
168+ -- Text objects: swap
169+ [" n|<leader>a" ] = map_callback (function ()
170+ ts_to_swap .swap_next (" @parameter.inner" )
171+ end )
172+ :with_silent ()
173+ :with_noremap ()
174+ :with_desc (" editn: Swap parameter.inner" ),
175+ [" n|<leader>A" ] = map_callback (function ()
176+ ts_to_swap .swap_next (" @parameter.outer" )
177+ end )
178+ :with_silent ()
179+ :with_noremap ()
180+ :with_desc (" editn: Swap parameter.outer" ),
181+ -- Text objects: move
182+ [" nxo|][" ] = map_callback (function ()
183+ ts_to_move .goto_next_start (" @function.outer" , " textobjects" )
184+ end )
185+ :with_silent ()
186+ :with_noremap ()
187+ :with_desc (" editnxo: Move to next function.outer start" ),
188+ [" nxo|]m" ] = map_callback (function ()
189+ ts_to_move .goto_next_start (" @class.outer" , " textobjects" )
190+ end )
191+ :with_silent ()
192+ :with_noremap ()
193+ :with_desc (" editnxo: Move to next class.outer start" ),
194+ [" nxo|]]" ] = map_callback (function ()
195+ ts_to_move .goto_next_end (" @function.outer" , " textobjects" )
196+ end )
197+ :with_silent ()
198+ :with_noremap ()
199+ :with_desc (" editnxo: Move to next function.outer end" ),
200+ [" nxo|]M" ] = map_callback (function ()
201+ ts_to_move .goto_next_end (" @class.outer" , " textobjects" )
202+ end )
203+ :with_silent ()
204+ :with_noremap ()
205+ :with_desc (" editnxo: Move to next class.outer end" ),
206+ [" nxo|[[" ] = map_callback (function ()
207+ ts_to_move .goto_previous_start (" @function.outer" , " textobjects" )
208+ end )
209+ :with_silent ()
210+ :with_noremap ()
211+ :with_desc (" editnxo: Move to previous function.outer start" ),
212+ [" nxo|[m" ] = map_callback (function ()
213+ ts_to_move .goto_previous_start (" @class.outer" , " textobjects" )
214+ end )
215+ :with_silent ()
216+ :with_noremap ()
217+ :with_desc (" editnxo: Move to previous class.outer start" ),
218+ [" nxo|[]" ] = map_callback (function ()
219+ ts_to_move .goto_previous_end (" @function.outer" , " textobjects" )
220+ end )
221+ :with_silent ()
222+ :with_noremap ()
223+ :with_desc (" editnxo: Move to previous function.outer end" ),
224+ [" nxo|[M" ] = map_callback (function ()
225+ ts_to_move .goto_previous_end (" @class.outer" , " textobjects" )
226+ end )
227+ :with_silent ()
228+ :with_noremap ()
229+ :with_desc (" editnxo: Move to previous class.outer end" ),
230+ -- movements repeat
231+ [" nxo|;" ] = map_callback (function ()
232+ ts_to_repeat_move .repeat_last_move_next ()
233+ end )
234+ :with_silent ()
235+ :with_noremap ()
236+ :with_desc (" editnxo: Repeat last move" ),
136237 },
137238}
138239
0 commit comments