In vim, e
is supposed to move me to the end of a word.
Let's say I have the following sentence:
|This is a sentence
where the |
indicates my current cursor position.
I would expect that hitting e
once would get me to the following state:
This| is a sentence
but surprisingly I end up with
Thi|s is a sentence
– I'm one character before the end of the word.
Consequently, if I hit ei
to append something to the end of the current word, it ends up putting me into insert mode just before the last character and screwing things up.
Two questions:
What am I not understanding regarding the e
motion, what is its use if it puts me just before the last char and not after the last char? What would be an example usage of it?
How do I quickly accomplish the following: Append something to the end of the word under the cursor
Thanks
ei
would be move to the end of the word and insert, which would be putting a new character before the current last one. ea
is what you'd want to move to the end and append.
To understand it, suppose you wanted to delete the last character of the word. You'd use ex
. If e
moved you past the end of the word, this wouldn't work, and yet you'd expect "move to the end of the word and then delete a character" would be equivalent to "delete the last character of the word". Think of e
as making the currently selected character (i.e. the one to insert before, or to append after, or to delete, or to switch case, or whatever) the last character of the word. In other words, the cursor is always on a character, rather than between two characters in the way that many GUI text editors work.
e
places you "on top" of the last character. For example, if you then hit r
and another key, you will replace the character at the cursor position, in this case the last character. If you want to input text after the cursor position, use a
instead of i
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With