In vim, prevent caret moving back when I leave edit mode?
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Beneath the City Looping
--
Chapters
00:00 In Vim, Prevent Caret Moving Back When I Leave Edit Mode?
00:41 Answer 1 Score 1
01:07 Accepted Answer Score 10
02:30 Answer 3 Score 1
03:01 Answer 4 Score 1
03:15 Thank you
--
Full question
https://superuser.com/questions/230081/i...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#vim
#avk47
ACCEPTED ANSWER
Score 10
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
ANSWER 2
Score 1
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.
ANSWER 3
Score 1
Since remapping <ESC>
is considered 'risky' I just combine with one of the Avoid the escape key approaches and have the following in my .vimrc
:
inoremap ii <ESC>l
Note: Make sure there are no space characters on the end of the line.
Simple, but fully certified as "works fine for me" as that is exactly what I'd otherwise have to type by hand.
Whether I use a
or i
I still get the caret moving back behaviour and it bugs the hell out of me as more often than not then next thing I want to type is d$
to delete to the end of a line, etc.
ANSWER 4
Score 1
Here's my solution:
au InsertLeave * call cursor([getpos('.')[1], getpos('.')[2]+1])
It's funny. This same question exists on all three sites: SO, SU, Unix+Linux.