[mini.ai] How to move_cursor backward
#2109
-
|
Note Inspired by chrisgrieser/nvim-spider. Let's define a textobject for selecting a subword: local MiniAi = require("mini.ai")
MiniAi.setup({
mappings = {
-- Move forward
goto_left = "g[",
goto_right = "g]",
},
custom_textobjects = {
e = {
{
"%f[%a]%l+%d*",
"%f[%w]%d+",
"%f[%u]%u%f[%A]%d*",
"%f[%u]%u%l+%d*",
"%f[%u]%u%u+%d*",It could also be useful to jump backward between subwords: vim.keymap.set("n", ",e", function() MiniAi.move_cursor("left", "a", "e", { n_times = vim.v.count1 }) end, { desc = "Next subword" })
vim.keymap.set("n", ",E", function() --[[ move backward ]], { desc = "Prev subword" })[1] See #1434 (comment) |
Beta Was this translation helpful? Give feedback.
Answered by
echasnovski
Nov 9, 2025
Replies: 1 comment 1 reply
-
|
This is already possible with local make_ai_jump = function(side, tobj_id, search_method)
return function() MiniAi.move_cursor(side, 'a', tobj_id, { n_times = vim.v.count1, search_method = search_method }) end
end
vim.keymap.set('n', ',e', make_ai_jump('left', 'e', 'cover_or_next'), { desc = 'Next subword' })
vim.keymap.set('n', ',E', make_ai_jump('left', 'e', 'prev'), { desc = 'Prev subword' })Adjust |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
drowning-cat
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is already possible with
opts.search_method='prev'. So something like this should work:Adjust
search_methodvalues to your liking (like'cover_or_prev'instead of'prev', etc.).