selectvimmultilinelines

Select text between double quotes over multiple lines in VIM


Let's say I have the following text:

"test 1
test 2
test 3"

I want to select everything between the quotes. I have used vi", but it does not work, it works only when the text is on a single line. On the other hand when when I have something like this:

(test1,
test 2)

and I type vi( it selects the entire text.

Any pointers would be greatly appreciated. Thanks


Solution

  • The text objects that are delimited by identical characters (", ') only work within a line, because otherwise it would be difficult to determine what's the right scope to select.

    If you want such a multi-line text object, you have to define your own alternative. Plugins like kana/vim-textobj-user or my own CountJump plugin help you with that.

    With the latter, this can be as simple as this to override the built-in i' / a' / i" / a":

    call CountJump#TextObject#MakeWithCountSearch('', "'", 'ai', 'v', "'", "'")
    call CountJump#TextObject#MakeWithCountSearch('', '"', 'ai', 'v', '"', '"')