evil icon indicating copy to clipboard operation
evil copied to clipboard

evil-select-parens selects next pair if not in parens

Open Garklein opened this issue 3 years ago • 1 comments

In modern versions of Vim (and Neovim), doing an action on something in parens will jump to the next instance of those parens and perform the action on them if you're not in those parens.

For example, if you are on the line int main(int argc, char **argv) { and type 0cib, it will change everything inside the parens even though you initially went to the beginning of the line. This pull request adds this functionality.

This feature already works on strings.

One bug is that if you yank something in parens and it needs to jump to the next pair because you're not in parens, in Vim it moves your cursor to the beginning of the next pair, while here it doesn't move your cursor. I couldn't figure out how to fix this.

Garklein avatar Sep 18 '22 16:09 Garklein

Thanks for this! I'm in hols right now but will take a look in a couple of weeks if no one beats me to it.

tomdl89 avatar Sep 18 '22 17:09 tomdl89

@Garklein before I take a proper look, will you add some tests? I can if you can't, but it may delay things a little.

tomdl89 avatar Sep 26 '22 17:09 tomdl89

Yep, here you go!

Garklein avatar Sep 27 '22 11:09 Garklein

Looks good. Two things I noticed:

  • di( doesn't move the cursor, but it should
  • vi( on empty parens only selects the second paren, but it should select both (although I'm not sure if I agree with vim on this)

tomdl89 avatar Sep 27 '22 15:09 tomdl89

@Garklein I put in some fixes. I decided I'm not interested in the edge case of vi( on empty parens 🤷 - take a look if you like - I'll merge if you're happy.

tomdl89 avatar Sep 27 '22 21:09 tomdl89

@tomdl89 Thanks for fixing that yank issue, I would never have figured that out!
I found one odd edge case that I will try and fix (if either the opening or closing paren is commented out, it stack overflows) -- after that, I'm good with this merge.

Garklein avatar Sep 28 '22 00:09 Garklein

Oh good spot! Yes please try to take a look - sounds a bit tricky.

tomdl89 avatar Sep 28 '22 18:09 tomdl89

@marcolgl Thank you for your contributions and thorough explanation! Everything looks good to me and I'm happy with this. @tomdl89 thoughts?

Garklein avatar Oct 02 '22 14:10 Garklein

Looks great. Thanks both! That's merged to master 🚀

tomdl89 avatar Oct 02 '22 19:10 tomdl89