开发者

Why does Vim position the caret one character off with $ (end of line)?

Observe a line in a Vim instance:

Why does Vim position the caret one character off with $ (end of line)?

Now I hit 开发者_开发知识库$:

Why does Vim position the caret one character off with $ (end of line)?

Why does my cursor not go all the way to the end? Once I try inserting, the text gets inserted before the last character! Even if I try to move right again while still in normal mode I get the bell. Oddly, when in edit mode I can move to the actual end of line with the right arrow key!

Why does Vim position the caret one character off with $ (end of line)?

Does anyone know why Vim does this? On 7.3 by the way. Thanks for the help.


Pressing $ while in command mode causes the cursor to move to the end of the line, effectively highlighting the last character. Hit i here to insert before the last character, or a to append to the line. It is slightly ambiguous here, because you're using a pipe character as a cursor rather than a rectangular block cursor. Have a look at ":help termcap-cursor-shape" if you want to change that.

If the goal is to append to the end of the line, A will jump to the end of the line and enter insert mode with a single keypress.


Use a to append a character after the current.

Or, to go to the end of the line and append in 1 step, use capital A. I.e. shiftA.

Similarly shift-I to insert at the beginning of the line without first having to press ^.


The cursor can't be between two characters, it is always on a character.

If you press $ then x, you will correctly delete the last printable character of the current line.

What you are observing is the fact that using i, you are always inserting your text before the selected character. If you want to insert after the selected character, you have to use a or better A as it has already been mentioned.

In other words:
i means "insert before character under cursor".
a means "insert after character under cursor".

mnemonic for a : a for "append".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜