3

How can I move to the next text object?

E.g. with cursor on the first , in

{}, {}, {}
  ^

then calling va} selects the middle {}. This is the behaviour I want to be able to achieve consistently, even in cases like this:

{{}, {}, {}}
   ^

This time, va{ selects the entire line.

How can I always move to the next text object? I.e., the cursor should not end up in an earlier position in the file after.

Here are the results of successively moving to the "next" a} text object as I consider it:

{{}, {{}, {}}, {}}
^
{{}, {{}, {}}, {}}
 ^
{{}, {{}, {}}, {}}
     ^
{{}, {{}, {}}, {}}
      ^
{{}, {{}, {}}, {}}
          ^
{{}, {{}, {}}, {}}
               ^

And after that, there is no "next" a} text object.

This should work across lines too, just like default text objects do. E.g. with the cursor in the first line first column (on the v) here, pressing vi{ selects the {} successfully.

vim stackexchange
text objects visual
mode {} movement

I hope the next-text-object movement will do the same.

3 Answers 3

2

Targets.vim provides the strangely named "next and last pair" custom text objects, which cover your notion of "next text object".

But there is no built-in normal mode "to next/previous text object" motion/command, so, unless you can put your hands on a plugin that explicitly provides it, you could probably try to work around that limitation by doing van}<Esc> (an} being provided by the aforementioned plugin).

1

For this specific object, one of f{va{ or /{Enterva{ will do. (I'm actually a little surprised that the last example worked.)

0

Module mini.ai from neovim plugin mini.nvim

Default mappings are

-- Next/last variants (similar to targets.vim)
around_next = 'an',
inside_next = 'in',
around_last = 'al',
inside_last = 'il',

-- Move cursor to corresponding edge of `a` textobject
goto_left = 'g[',
goto_right = 'g]',
  • select left (last) val{ or valb
  • select right (next) van} or vanb

As far as I have checked g[b and g]b do not work as you expect. Maybe check with the author of mini.ai if there is something what can be done.

1
  • Do you know how it works?
    – minseong
    Apr 17, 2023 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.