2

Maybe it was discussed many times (I strongly believe), but I could not formulate my question properly. So lets imagine we have this sequence of words:

foo bar baz

Applying 3e will move us onto:

foo bar ba|z

where pipe character is the position of the cursor, but why? As far as I can read the docs e moves you to the end of the next word starting from the current position,. Shouldn't we end up like:

foo bar baz|

?

Or is this relevant to the idea that final position after applying of the combination should be still placed within a sequence, while baz| is outside this?

  • the only reason 3w moves you there is because the cursor cannot go past the end of the buffer. w moves to the starts of words, not the ends – Mass Mar 24 '18 at 20:10
  • @Mass, oh, I meant e not w fixed the original question – M.Mass Mar 24 '18 at 20:51
10

This is assuming that your setup is using the ordinary e. If this doesn't answer your question, check if e is mapped to anything with :nmap e


This comes from a fundamental misunderstanding of where vim's cursor is situated. In insert mode, vim functions like a traditional editor, and the cursor goes between characters. So you can have the cursor situated like this:

foo bar ba|z

with the cursor between the 'a' and the 'z'. However, this is impossible in normal mode. In normal mode, rather than having the cursor between characters, you'll have it on a single character. So instead of between the 'a' and the 'z', you'll have it here:

          v
foo bar baz

or here:

         v
foo bar baz

but never here:

foo bar ba|z

One way to make this difference more apparent is to make the cursor shape a bar in insert mode and a block in normal mode. The block will be positioned over the character the cursor is on. This vim tips describes how to set that up.

1

The result is not to put the cursor between the a and z (as the pipe character seems to illustrate in your example) but to put the cursor on the z. In normal mode the cursor sits on top of a character rather than being between characters. (Think of what the replace command does. Wouldn't really work if the cursor was between characters.) Based on that, the definition of "to the end of word", which is how help describes it, is no longer ambiguous. Since it doesn't say before the end of word or after the end of word there is just one choice: on the last element of the word, i.e. z.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.