VI 编辑器:移至 EOL 而不是最后一个字符 [英] VI Editor: Move to EOL instead of last character

查看:27
本文介绍了VI 编辑器:移至 EOL 而不是最后一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常发现自己不得不在极简终端上使用普通的旧 vi,而这些终端的行为往往与大型发行版上的 vim 不同,因此这种行为让我感到困惑.

I'm most often finding myself having to work with plain old vi on minimalistic terminals that tend to act differently than the vim on big distros, and so the behavior trips me up.

我想知道的不是如何移动到行中的最后一个字符,而是过去一个字符.因为输入 $ 不会将插入光标移动到行中的最后一个字符,这很容易证明.我现在在 MSYS 上使用 vi.

What I want to know is not how to move to the last character in the line, but one character past that. Because typing $ does NOT move the insertion cursor to the last character in the line, and this is easily proven. I'm using vi on MSYS right now.

如果我输入一行

这是一个测试

并点击esc$i,我将得到以下信息:

and hit esc, $, i, and <enter>, I will get the following:

This is a tes
t

这表明插入光标没有放在行尾,而是放在行中最后一个字符的左侧(想象一下这个框是像 Notepad++ 中的一行.框在字母的顶部,表示该字符将被插入到组成框左侧的区域中),我知道这一点,因为如果它真的在末尾(结束"的意思是右边的最后一个字符)最后一个字符不会移动到它自己的行,如您在上面看到的那样.

This shows that the insertion cursor was not put at the end of the line, but one to the left of the last character in the line (Imagine the box being a line like in Notepad++. The box is over the top of the letter, signifying that the character will be inserted in the area that makes up the box's left side), and I know this because if it were really at the end ("end" meaning to the RIGHT of the last character) the last character would not be moved to its own line such as what you see above.

我不想要这种行为.每次按 Enter 键时都要输入一个额外的字符,以确保我不必重新输入单词,这对我来说太痛苦了.这会降低我的工作效率.

I don't want this behavior. It's too much a pain for me to type one extra character every time I press enter just to ensure I don't have to retype my words. This kills my productivity.

我该如何解决这个问题?这是我可以在 .exrc 中调整的设置吗?

How do I fix this? Is it a setting I can tweak in .exrc?

推荐答案

行尾进入插入模式的普通模式命令为A.

The normal mode command for entering insert mode at the end of the line is A.

更一般地,i 在当前字符之前进入插入模式,所以你得到的与你所做的完全一致:$ puts光标在最后一个字符上,i 在最后一个字符前进入插入模式.这就是你要求 Vim 做的事情,这就是它所做的.

More generally, i enters insert mode before the current character so what you get is perfectly in line with what you do: $ puts the cursor on the last character and i enters insert mode before the last character. That's what you ask Vim to do and that's what it does.

如果你想在当前字符之后进入插入模式,正确的命令是a所以你应该做的而不是$i(不能做你想做的事,不管你是在 vi 还是 vim)是 $a 有一个很酷的快捷方式:A.

If you want to enter insert mode after the current character, the right command is a so what you should have done instead of $i (which can't do what you want, whether you are in vi or vim) is $a for which there is a cool shortcut: A.

这篇关于VI 编辑器:移至 EOL 而不是最后一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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