CamelCaseMotion icon indicating copy to clipboard operation
CamelCaseMotion copied to clipboard

Changing words deletes a trailing underscore

Open oconnor663 opened this issue 11 years ago • 14 comments

Normal vim behavior:

  • Start with the line "three words here". Put the cursor on the start of "words".
  • Typing 'dw' deletes "words" and also the space after it.
  • Typing 'cw' deletes "words", preserving the spaces on both sides, before dropping into insert mode.

CamelCaseMotion behavior:

  • Start with the line "three_words_here".
  • 'd,w' works as above, deleting the underscore after "words"
  • Bug: 'c,w' doesn't work as above. Instead, it deletes the trailing underscore like 'd,w'. After the word is changed, the underscore has to be retyped. The expected behavior would be for the trailing underscore to remain.

Awesome plugin, by the way, thanks a million!

oconnor663 avatar Sep 19 '12 00:09 oconnor663

Good point, I'll take a look when I get some time.

All thanks should be directed to @inkarkat for authorship of the plugin.

bkad avatar Sep 19 '12 00:09 bkad

The c,w mapping includes the whitespace after the word, but built-in cw does not. This is a Vim special case that custom motions cannot replicate. Cp. :help cw

If you want the trailing underscore to remain, use c,e.

@bkad: Thanks for including me on the discussion. I guess I'll watch your repo now to be informed of the issues that arrive here. Seems like many people don't fully realize that yours is just a fork, or find it easier to complain here.

inkarkat avatar Sep 19 '12 09:09 inkarkat

@inkarkat It's because we couldn't find your github. I looked through your projects and couldn't find camelcasemotion. Is there a place to file issues against your repo?

dlee avatar Sep 19 '12 10:09 dlee

@inkarkat @oconnor663 What about mapping c,w to whatever implements c,e? Would that cause unexpected behavior in certain scenarios?

dlee avatar Sep 19 '12 10:09 dlee

@bkad: You may be too young to know this, but there was software development before GitHub :-) Just send issues and patches to me via email (the address is listed in the script's header and help file).

I do know the benefits of GitHub; I just haven't moved my own Vim plugins there.

inkarkat avatar Sep 19 '12 10:09 inkarkat

@inkarkat You may be too old to realize this, but issue tracking happens on an issue tracker for open source projects nowadays :-)

On a serious note, you have a github account, but the camelcasemotion project isn't listed, so it's easily assumed that you're not maintaining it anymore. The last update before you found this github repo was in 2009.

You should really consider moving your vim plugins to github.

dlee avatar Sep 19 '12 10:09 dlee

This is interesting. Here's some more discussion of the builtin vim behavior: https://groups.google.com/forum/?fromgroups=#!topic/vim_use/iLZJm7ywh40

I notice that ciw has similar special casing to cw, and that ci,w lacks that special casing just like c,w. However, ci,e seems to do the Right Whitespace Thing just like c,e did, even though cie isn't actually a command that exists.

I'm unfamiliar with vimscript, so maybe this is a stupid question, but is there any good way to simply map c,w and ci,w to the e variants by default in the plugin? Or would that make questionable assumptions about the user's keybindings?

oconnor663 avatar Sep 19 '12 17:09 oconnor663

Try

:nmap c,w c,e
:nmap ciw cie

If you don't run into problems with that (I don't see why you should), I could add this to the plugin, either as a configurable default (when you use the default mappings) or a note in the documentation to apply the special case. What are your thoughts? I have never relied on this special case, so I don't know whether the majority of users would expect this or rather find this strange.

inkarkat avatar Sep 19 '12 20:09 inkarkat

I think @inkarkat means

:nmap ci,w ci,e

for the second line.

Also: cool. I've been annoyed by this but not quite aware of why. Will try those mappings.

henrik avatar Mar 20 '13 07:03 henrik

This won't fix things like c2,w of course, but I'll take what I can get.

henrik avatar Mar 20 '13 07:03 henrik

I've used the suggested mappings since my last comment; haven't had any problems.

henrik avatar May 28 '13 06:05 henrik

I seem to be having some similar issue. Placing the cursor on the 's' in 'sent' in the following:

return $this->sentAt;

and typing ciw, I end up in insert mode with a space (and my cursor) just before A:

return $this-> At;

trq avatar Feb 04 '14 05:02 trq

To be comprehensive, you can also add this line to your vimrc: :nmap di,w di,e

This is in addition to the aforementioned:

:nmap c,w c,e :nmap ci,w ci,e

Asheq avatar Aug 22 '16 20:08 Asheq

Very useful - should be a default feature!

gerazov avatar Nov 04 '21 13:11 gerazov