在插入模式下遍历文本 [英] Traversing text in Insert mode

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

问题描述

在 Vim 的插入模式中,除了使用箭头键之外,还有什么方法可以前后移动某些字符来遍历文本吗?

While in Insert Mode in Vim, is there any way to traverse the text moving some characters forward and backward other than using the arrow keys?

如果我在插入模式下按 hjkl,实际字符是打印在屏幕上,而不是在文本中移动.

If I press h, j, k and l while in Insert mode, the actual characters are printed on screen instead of moving through the text.

我目前的做法是使用 Ctrl + [ (Esc) 然后遍历文本;但显然这没有成效.

The way I'm doing it at the moment is having to resort to Ctrl + [ (Esc) and traversing the text then; but obviously that is not productive.

推荐答案

虽然您应该能够使用 h j k l 键在插入模式下遍历编辑器,但这实际上不是 Vim 的使用方式!Vim 提供了许多命令来使编辑变得更快.

While it may make sense that you should be able to use the h j k l keys to traverse the editor in insert mode, but that is actually not the way Vim is intended to be used! There are many commands that Vim provides to make editing faster and easier.

正确的方法Esc,去你想要做的小修正,修复它,返回并继续编辑.它是有效的,因为 Vim 比通常的字符向前/向后/向上/向下移动更多.在您了解更多之后,这会变得更有成效.

The right way is to press Esc, go where you want to do a small correction, fix it, go back and keep editing. It is effective because Vim has much more movements than usual character forward/backward/up/down. After you learn more of them, this will happen to be more productive.

这里有几个用例:

  • 您不小心输入了不小心".没问题,序列EscFfrdA 将纠正错误并将您带回编辑的位置.Ff 移动会将光标向后移动到第一个遇到的f"位置.特点.与 Ctrl+DeldEnd,它在休闲编辑器中的作用几乎相同,但需要更多的击键并使您的手移出键盘的字母数字区域.
  • 您不小心输入了您不小心输入了",但想将其更正为您故意输入".然后 Esc2bcw 将删除您要修复的单词并带您进入插入模式,因此您可以立即重新输入.要返回编辑状态,只需按 A 而不是 End,这样您就不必移动手来到达 End 键.
  • 您不小心输入了鼠标"而不是老鼠".没问题 - 旧的 Ctrl+w 将删除前一个单词而不离开插入模式.擦除一个小字比修正其中的错误要快得多.我太习惯了,以至于我在输入这条消息时关闭了浏览器页面...!
  • 重复计数在很大程度上未得到充分利用.在进行动作之前,您可以输入一个数字;并且运动将重复此次数.例如, 15h 将使光标返回 15 个字符,4j 将光标向下移动 4 行.开始使用它们,您很快就会习惯.如果您在光标后十个字符处出错,您会发现按 键 10 次比移动光标的迭代方法慢得多.因此,您可以快速键入键 12h(粗略地猜测移动光标需要返回多少个字符),并立即用 ll 向前移动两次以快速纠正错误.
  • You accidentally typed "accifentally". No problem, the sequence EscFfrdA will correct the mistake and bring you back to where you were editing. The Ff movement will move your cursor backwards to the first encountered "f" character. Compare that with Ctrl+DeldEnd, which does virtually the same in a casual editor, but takes more keystrokes and makes you move your hand out of the alphanumeric area of the keyboard.
  • You accidentally typed "you accidentally typed", but want to correct it to "you intentionally typed". Then Esc2bcw will erase the word you want to fix and bring you to insert mode, so you can immediately retype it. To get back to editing, just press A instead of End, so you don't have to move your hand to reach the End key.
  • You accidentally typed "mouse" instead of "mice". No problem - the good old Ctrl+w will delete the previous word without leaving insert mode. And it happens to be much faster to erase a small word than to fix errors within it. I'm so used to it that I had closed the browser page when I was typing this message...!
  • Repetition count is largely underused. Before making a movement, you can type a number; and the movement will be repeated this number of times. For example, 15h will bring your cursor 15 characters back and 4j will move your cursor 4 lines down. Start using them and you'll get used to it soon. If you made a mistake ten characters back from your cursor, you'll find out that pressing the key 10 times is much slower than the iterative approach to moving the cursor. So you can instead quickly type the keys 12h (as a rough of guess how many characters back that you need to move your cursor), and immediately move forward twice with ll to quickly correct the error.

但是,如果您仍然想在不离开插入模式的情况下进行小文本遍历,请遵循rson建议 并使用 Ctrl+O.以我上面提到的第一个示例为例,Ctrl+OFf 会将您移至上一个"f"字符并让您处于插入模式.

But, if you still want to do small text traversals without leaving insert mode, follow rson's advice and use Ctrl+O. Taking the first example that I mentioned above, Ctrl+OFf will move you to a previous "f" character and leave you in insert mode.

这篇关于在插入模式下遍历文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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