"ce" deletes two words if the current one is 1-letter long?

75 views
Skip to first unread message

François Ingelrest

unread,
Jun 3, 2008, 11:13:27 AM6/3/08
to vim...@googlegroups.com
Hi all,

I frequently use "ce" to replace the current word, so I go to the the
beginning of that word and type "ce". I've noticed that when the
current word is 1-letter long, the following word gets deleted too.
For instance, if I place the cursor on the 'a' of "an objective" and
type "ce", I replace only "an". If I do the same thing with "a
server", I replace both words.

Is that really the intended behavior? Shouldn't "changing until the
end of the current word" stop at the current cursor position if that
current word is 1-letter long?

Benjamin Fritz

unread,
Jun 3, 2008, 11:51:50 AM6/3/08
to vim...@googlegroups.com

The problem with this would be that 'e' needs to be able to move from
word to word. If it stays in place when the cursor is on a 1-letter
word, the cursor would be "stuck" on that word, unable to progress to
the next with a subsequent keypress. Note, for changing a
single-letter word, you can train yourself to use the "s" command
instead, which is a synonym for "cl".

François Ingelrest

unread,
Jun 3, 2008, 11:57:06 AM6/3/08
to vim...@googlegroups.com

While I understand your argument about jumping through words, it seems
quite strange to me that I need to take care of whether the current
word has multiple letters or not. Of course I can get used to "s", but
it's just strange that I need to take care of that. Maybe I can remap
"ce" to use either "ce" or "s" based on the length of the current
word?

Benjamin Fritz

unread,
Jun 3, 2008, 12:30:40 PM6/3/08
to vim...@googlegroups.com

Actually, an alternate idea that has proved infinitely more useful to me:

Use text-objects. Instead of "ce" try using "ciw" which will work on
words of all lengths and is (I have found) usually what I want to do
anyway.

See :help text-objects and :help iw

Benjamin Fritz

unread,
Jun 3, 2008, 12:32:26 PM6/3/08
to vim...@googlegroups.com

In addition, text-objects can be used with the cursor _anywhere_
within the word, instead of requiring you to place the cursor at the
beginning of the word.

Gary Johnson

unread,
Jun 3, 2008, 12:43:27 PM6/3/08
to vim...@googlegroups.com

The problem is your misunderstanding of the meaning of 'e'. It does
not mean "go to the end of the word." It means "go forward to the
next end of a word." You have assumed a meaning from your
experience with e's behavior when your cursor is at the start of a
multi-letter word. That assumption was reasonable in that context,
but it was incorrect.

You may find it useful to use 'cw' in place of your current use of
'ce'. 'cw' should behave consistently and always change from the
cursor to the end of the current word. See

:help w
:help iw

'ciw' will change the entire current word even when the cursor is
not at the start of the word.

Regards,
Gary

Charles E Campbell Jr

unread,
Jun 3, 2008, 12:40:55 PM6/3/08
to vim...@googlegroups.com
François Ingelrest wrote:
> While I understand your argument about jumping through words, it seems
> quite strange to me that I need to take care of whether the current
> word has multiple letters or not. Of course I can get used to "s", but
> it's just strange that I need to take care of that. Maybe I can remap
> "ce" to use either "ce" or "s" based on the length of the current
> word?
>
Its a philosophy thing, IMHO. I think you're thinking of "ce" as a
command; "ce" is not a command. "c" is. "e" is a motion. The
combination "ce" may be interpreted to mean: "change from here to
wherever the "e" motion takes the cursor".

Regards,
Chip Campbell

François Ingelrest

unread,
Jun 3, 2008, 2:22:14 PM6/3/08
to vim...@googlegroups.com
On Tue, Jun 3, 2008 at 6:30 PM, Benjamin Fritz <fritzo...@gmail.com> wrote:
> Actually, an alternate idea that has proved infinitely more useful to me:
>
> Use text-objects. Instead of "ce" try using "ciw" which will work on
> words of all lengths and is (I have found) usually what I want to do
> anyway.
>
> See :help text-objects and :help iw

Thanks, I wasn't aware of that. That's what is nice with Vim, you
always learn something new :)

On Tue, Jun 3, 2008 at 6:43 PM, Gary Johnson <gary...@spk.agilent.com> wrote:
> You may find it useful to use 'cw' in place of your current use of
> 'ce'. 'cw' should behave consistently and always change from the
> cursor to the end of the current word. See

Once again something new :)
I actually never tried "cw" since I would have thought it would have
eaten the space as well.

John Little

unread,
Jun 3, 2008, 6:30:34 PM6/3/08
to vim_use

On Jun 4, 6:22 am, "François Ingelrest" <athro...@gmail.com> wrote:
> I actually never tried "cw" since I would have thought it would have
> eaten the space as well.

"cw" is a special case, inherited from vi. It breaks the usual
operator - motion separation. Note that :help cw explains the special
case, but is inaccurate in your extra-special case, in that it says cw
works the same as ce; for one character words, cw does what you want,
not ce.

It's worth learning the "s" though, especially in code. I used vi for
years before discovering "s", then found myself using it to save a
keystroke very often, often with a count.

HTH, John

Ben Schmidt

unread,
Jun 3, 2008, 8:21:23 PM6/3/08
to vim...@googlegroups.com
> The problem is your misunderstanding of the meaning of 'e'. It does
> not mean "go to the end of the word." It means "go forward to the
> next end of a word." You have assumed a meaning from your
> experience with e's behavior when your cursor is at the start of a
> multi-letter word. That assumption was reasonable in that context,
> but it was incorrect.
>
> You may find it useful to use 'cw' in place of your current use of
> 'ce'. 'cw' should behave consistently and always change from the
> cursor to the end of the current word. See
>
> :help w
> :help iw

Hehe. I had never realised that 'cw' behaves consistently in this fashion, but it
is very nice. I will be using it, as I had the same problem with 'e' and none of
the other solutions work for me: I usually use 'ce' or 'de' once and then '.' a
whole stack of times, so substituting 's' when I come to a single letter word is
not an option, nor are text objects as I am often changing or removing word tails
or suffixes.

Pity it's completely inconsistent with the usual motion of 'w', and with 'w' with
other operators, though. That was the assumption I made: that 'cw' would change
the same text that 'dw' deleted. Wrong!

Grins,

Ben.

Reply all
Reply to author
Forward
0 new messages