emacs-evil / evil-surround

you will be surrounded (surround.vim for evil, the extensible vi layer)
Other
631 stars 61 forks source link

Use vimlike `csw` #147

Closed tam5 closed 5 years ago

tam5 commented 5 years ago

In vim, i used to do csw' all the time, which in the following example hovering inside 'Hello' would change

Hello, World!

to

'Hello', World!

with evil-surround it seems instead i have to do ysiw'.

Maybe I am crazy and should just relearn the new binding, but is there any way to get csw to work exactly like vim did?

edkolev commented 5 years ago

Last time I used vim, cs was used to change surroundings, while ys was used to add them (mnemonic for you surround). Are you sure you haven't changed the default vim bindings?

ninrod commented 5 years ago

strangely enough, yes, in stock vim with vim-surround csw' does what you say, which I find rather odd. ysw' is what you really would mean. you could drop the i.

edkolev commented 5 years ago

I just found out - this is actually documented behaviour:

The letters w, W, and s correspond to a |word|, a |WORD|, and a |sentence|,
respectively.  These are special in that they have nothing to delete, and
used with |ds| they are a no-op.  With |cs|, one could consider them a
slight shortcut for ysi (cswb == ysiwb, more or less).

https://github.com/tpope/vim-surround/blob/master/doc/surround.txt

ninrod commented 5 years ago

yeah, seems like we have to fix it. thanks for reporting @tam5. PRs welcome by the way.

ninrod commented 5 years ago

good catch @edkolev

ninrod commented 5 years ago

I must say though, it makes the "api" a bit bizarre. cs (change surrounding) obviously takes a surrounding, and a word isn't a surrounding. Very confusing if you ask me.

tam5 commented 5 years ago

I could argue that it makes some sense since you are changing what's surrounding the word with something else. Honestly though, its just what my fingers do now... and I'd rather press 4, somewhat close together keys, than 5 all over the place keys.

Took a quick look, but given this is indeed sort of a shortcut that breaks the mold, it wasn't immediately clear how it should be implemented. Any suggestions?

ninrod commented 5 years ago

yes, I think the fix lies within this snippet. It is a possibility that you might have to fix the evil-surround-valid-char-p key function because I suspect that w would not qualify as a valid char as per the function. As always, be sure to implement tests if you follow through with the PR.