Why isn't the whole command repeated? #54

Closed
jnicklas opened this Issue Mar 14, 2012 · 7 comments

Comments

Projects
None yet
2 participants

This has been bothering me for ages, but maybe I'm just doing something wrong.

I have vim-repeat installed and it dutifully repeats commands, but it doesn't repeat the entire command. Say I do ysiw" to surround a single word with double quotes, and now I move the cursor to a different word and hit ., I would just expect that word to be surrounded with double quotes. Instead, I need to strike " again.

So usually this goes ysiw"j."j."j."j."j."j."j.", etc... It would be so much faster if I could just do ysiw"j.j.j.j.j.j.j.. And in my opinion that's more inline with how vim's other commands behave (e.g. ciw).

Am I doing something wrong, or is this intentional? If so, why?

This is even worse with HTML tags. ysiw<a>\Rj.<a>\Rj.<a>\Rj.<a>\Rj.<a>\Rj.<a>\Rj.<a>\Rj.<a>\R. Arrrrgggghh.

Owner

tpope commented Mar 14, 2012

I wouldn't call it intentional, but it is an unfortunate limitation of how Vim handles operator maps. When you press ysiw, the end result is that Vim calls a function and tells it something like "line 12 column 34 through line 12 column 39". Nowhere does it provide us with iw, and thus there's no way for us to record it for next time. Instead, Vim's built in repeat operator takes over and screws it up.

Luckily for you, the particular use case of iw has a simple workaround: press csw". I added this when feeling the exact same pain you are.

As far as the HTML tag stuff goes, it's probably solvable, just tricky. See #31 for a failed attempt.

Owner

tpope commented Mar 14, 2012

Scratch that last part. The HTML thing has been solved.

Owner

tpope commented Mar 14, 2012

Holy crap! Drawing my attention to the way . almost works has given me a brilliantly simple idea: call the native . from the overridden .. It works!

This is probably applicable to commentary.vim and unimpaired.vim as well. Oh frabjous day!

tpope closed this in dfea25a Mar 14, 2012

Owner

tpope commented Mar 14, 2012

Even better, it already works on commentary.vim and unimpaired.vim. I had just always assumed the worst. I'm hoping something has changed in Vim since I first wrote surround.vim because it's disappointing to think I would have missed this the first time around.

Seems to work nicely with stuff like brackets and quotes, but doesn't work with html tags it seems. Though csw is awesome and seems to work fine with all variations I can throw at it, thanks for pointing that out :)

Owner

tpope commented Mar 14, 2012

Didn't try that particular edge case. Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment