进入插入模式时的光标定位 [英] Cursor positioning when entering insert mode

查看:36
本文介绍了进入插入模式时的光标定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Vim 中切换到命令模式时,当光标位于单词末尾或单词上时,以及当我使用 $,它不会到达实际的行尾,而是在最后一个单词的末尾前一个字符,并且 l ("el") 不会向前移动它,我必须使用箭头键到达那里.

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)?

推荐答案

如果使用 gvim 会更清楚一些,光标会在此处发生变化.

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

gvim 中的插入模式将光标作为 I 型梁,因为您键入的下一个字母将插入在 | 之后.正常模式具有块光标,因为您接下来键入的内容可能只会影响当前突出显示的字母(例如,如果您使用 x、s 等).所以插入模式实际上是添加文本,而普通模式是通过某种方式修改文本.

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



([] 表示块光标在那个 h 上)

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

假设你有 t[h]is text

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





如果此时按下 i,光标将如下所示(在 gvim 中)(| 是插入模式光标)





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

假设你有 t|他的文字

Let's say you have t|his text





如果你按下 a 而不是 i,它看起来像这样





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

假设您有此|is 文本

Let's say you have th|is text





另一件要记住的事情(如 pavanlimo 提到的),从正常模式,您可以使用光标在行的第一个字符之前或最后一个字符之后进入插入模式,使用 shift-I 或 shift-A.





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.

这篇关于进入插入模式时的光标定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆