Cursor positioning when entering insert mode

it is a little more clear if you use gvim, where the cursor changes.

insert mode in gvim has the cursor as an I-beam, since the next letter you type will be inserted after the |. normal mode has the block cursor, because the next thing you type may just effect the letter that is currently highlighted (like if you use x, s, etc). So insert mode is actually adding text, but normal mode is modifying text in some way.

So in normal mode, jumping to the end of the line really just means the last character, since that is the last thing that is possible to be modified. in insert mode, the cursor goes passed the last character, since it is possible to add things afterwards.

One thing to keep in mind is that you can control which side of the block you end up on going from normal mode to insert mode



([] means that the block cursor is over that h)

Let's say you have t[h]is text





if you pressed i at this point, the cursor would look like this (in gvim) (| being the insert mode cursor)

Let's say you have t|his text





if you pressed a instead of i, it would look like this

Let's say you have th|is text





Another thing to keep in mind (as pavanlimo mentioned), from normal mode you can go to insert mode with your cursor just before the first character of the line, or just after the last character, with shift-I or shift-A.


I'm not quite sure of the reasoning behind it, but you can work around it by pressing:

Shift + a

You might be interested in the option virtualedit and the following value:

set virtualedit=onemore

With this option you can move the cursor one character over the end of the line and then press i to insert mode after the last character.

This solves the issue in a way but personally I find this behavior a bit odd. Only in a few cases you encounter the problem so it might be worth ignoring it ;-)

Tags:

Vim