Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cursor positioning when entering insert mode

Tags:

vim

When I switch to command mode in Vim, the cursor seems to move one character back when it's at the end of or on a word, and when I go to the end-of-line with $, it does not go to the actual end of line but one character before the end of the last word, and l ("el") does not move it forward and I have to use the arrow key to get there.

I haven't been able to find documentation of this behavior, but this seems strange to me. What's the reasoning behind this (for my own curiosity), and how can I get around it (or deal with it)?

like image 997
hatmatrix Avatar asked Sep 09 '10 12:09

hatmatrix


People also ask

How do I get my cursor to move in insert mode?

Command mode is used for cursor movement, editing, retrieving and saving files, etc. If you want to type in text, you need to be in Insert mode. To move from Command mode to Insert mode, press "i" (no quotes). To move from Insert mode to Command mode, press "ESC" (the Escape key).

How do you enter insert mode and go to the beginning of the line?

Esc + i to exit insert mode and enter it again, effectively going to the beginning of line.

Which key is used for entering insert mode?

Command Mode vs. To enter text, you must enter insert mode. If in insert mode, enter command mode by hitting the escape, <esc>, key.

How do you enter insert mode in vim?

To go into INSERT mode from COMMAND mode, you type i . To go back to COMMAND mode, you type the esc key. vim starts out in COMMAND mode. Over time, you will likely spend more time in COMMAND mode than INSERT mode.


1 Answers

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.

like image 186
Matt Briggs Avatar answered Oct 03 '22 21:10

Matt Briggs