multichange.vim icon indicating copy to clipboard operation
multichange.vim copied to clipboard

Doesn't work properly with change motions

Open thalesmello opened this issue 8 years ago • 3 comments

Suppose that I have the following snippet.

Hello mister Thomas
Hello mister Scott
Hello mister Edward

And that, from the first character in the first line, I type c2eGood morning<esc>

The result would be

Good morning Thomas
morning mister Scott
morning mister Edward

thalesmello avatar Jan 17 '17 19:01 thalesmello

I use the plugin mostly for variable renaming, and I find it very convenient that, if you edit a word with cw, it replaces only that word. So, replacing "one" with "two" will not touch "one_more_thing". On the other hand, whever I do want to replace anything without caring about word boundaries, I'd use visual mode.

In practice, in normal mode, the pattern is the word under the cursor wrapped in \< and \>, while in visual mode, it's the selected text wrapped in \V and \m (to avoid matching special characters).

Now, I'm pretty sure it's possible to just take the text that the motion operated on, and act on it the same way I do with visual mode. But that would drop the word functionality. I could add \< and \> on the text in normal mode, but I feel that wouldn't make sense in all cases.

An option might be to manually compare the text that the motion selected (only in normal mode) with the current <cword> and, if they're the same, add word boundaries. Not sure if that makes sense or not.

I'll think about it and see what I can do. If you can think of a sensible way for the plugin to work with word boundaries and text objects, let me know your thoughts.

AndrewRadev avatar Jan 18 '17 16:01 AndrewRadev

That's exactly what I would expect from a multiple word replacement.

  • When you change motion a single word, do include \< and \> in the search.
  • When you change motion more than one word, make it behave the same way as visual mode.

Do you think it would be very complicated to implement?

Otherwise, I'd just accept this as a limitation and just use visual mode whenever I need this.

thalesmello avatar Jan 18 '17 16:01 thalesmello

I'll try to implement it and see how it goes.

AndrewRadev avatar Jan 18 '17 16:01 AndrewRadev