0

When I use vi( (or vib or vi)) to select the inner-part of brackets, everything works fine whenever there is some content but as soon as the brackets are empty or contain only linebreaks, the previous bracket content is selected.

I would assume that the text-object should just fail (no selection) as it does when the cursor isn't between brackets.

Question: does this behavior seem normal to you or should I investigate more and possibly raise an issue on the official repo (and maybe try to fix it and create a pull request).

Examples: In the following, cursor position is given by {} and highlighted text with [...]

(some text){(}) => vib => ([some text])()

(some text){(}  => vib => ([some text])(
)                         )

Examples: When the cursor is on the closing bracket of the empty field, the result is slightly different: only the last bracket is selected (nothing should be selected).

 (some text)({)} => vib => (some text)([)]

 (some text)(    => vib => (some text)(
{)}                       [)]

Last Example When several empty brackets are used, vib select the pair of previous brackets.

()(){(})  => vib => ()[()]()

Edit

I understand that selecting the inner part of a (mostly) void pair of bracket is useless, believe-me :) The reason I stumbled upon this behavior is because I was writing a text-object script that relies on ib text-object and that was sometimes failing for this reason.

6
  • 1
    Welcome to Vim! Could you tell us what is your question? Why do you want to select the content of a bracket pair that is empty? I suppose we need more context to give you a useful answer :-) Nov 9, 2023 at 14:54
  • 1
    Note that you can't select 0 characters (the contents of ()). I think vab would select the parens you are interested in.
    – D. Ben Knoble
    Nov 9, 2023 at 15:08
  • Thanks for your feedbacks! @VivianDeSmedt: fair remark, I edited the question.
    – Laurent'
    Nov 10, 2023 at 9:04
  • 2
    @Laurent may you should ask the question about the text object that you try to built. Some of the expert could have some suggestion about how to address your problem. Otherwise your question looks more like a "bug" report that should be posted to the Vim github (although I have some doubts that the behavior you have detected could be changed in a backward compatible way and be accepted as a bug :-| Nov 10, 2023 at 9:15
  • Thanks, will do, sorry for the noise :)
    – Laurent'
    Nov 10, 2023 at 10:36

1 Answer 1

1

This has been improved/fixed in vim 9.1.0012

https://github.com/vim/vim/commit/3779516988f14f2070d827514c79383334a0946b

2
  • Indeed, thanks for reporting here. This is the result of the bug report I filed.
    – Laurent'
    Jan 17 at 12:31
  • 1
    I know, this is just to make the question "complete".
    – Maxim Kim
    Jan 17 at 22:04

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.