In vim, prevent caret moving back when I leave edit mode?

Solution 1:

This question gets asked frequently among new vi/Vim users, and the answer is that while in normal mode, the cursor is always "on" a character, but in insert mode the cursor is always "between" two characters (remember, the end-of-line is a character). You can't really see this illustrated as well in console Vim, but in the GUI you'll notice the cursor becomes a bar between two characters when you enter insert mode, instead of a block over a character when you are in normal mode.

So what you're seeing is not necessarily the cursor moving one character back when you leave insert mode, but merely moving onto a character. The only safe direction of movement is to the left (or back). Thus, you have more than one way of entering insert mode:

  • "a" enters insert mode with the cursor "between" the character the cursor was on and the next character to the right.
  • "i" enters insert mode with the cursor "between" the character the cursor was on and the previous character to the left.

Some people have made efforts to suppress this "movement" that they don't like, but it inevitably interferes with plugins and other Vim scripts they want to run in the future.

My suggestion is to get used to using the "a" and "i" (and "A" and "I") commands in the appropriate circumstances.

The "o" and "O" commands are also useful to learn. See:

:help a
:help i
:help A
:help I
:help o
:help O

Edit: If you're still determined to change this behavior, try this tip: Prevent escape from moving the cursor one character to the left

Solution 2:

I think by carat you mean your cursor and if you are using "i" this will insert directly where your cursor is, "a" (which I believe you are looking for) moves the cursor one character to the right. Also, shift-i(I) will go to the begining of the line and shift-a(A) will go all the way to the end of the line.

If I have misunderstood your question I apologize.