在VIM上达到目标的最有效方法是什么? [英] What is the most efficient way to reach a spot on sight on VIM?

查看:64
本文介绍了在VIM上达到目标的最有效方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您在640行上,并在671行上注意到以下内容:

Suppose you are on line 640 and notice the following on line 671:

if (jumps_over(quick_fox[brown],the_lazy_dog)) the_lazy_dog.bark(); 

导航到树皮"最有效的方法是什么?

What would be the most key efficient way to navigate to "bark"?

推荐答案

这是对Vim的常见误解:Vim并非旨在提高效率.

Vim旨在以可重复的,通常是复杂的组合使用小型构建基块,以实现您的目标.这不是一个固有的高效过程,但是对于一部分复杂任务而言,它很有用.例如,[运动] [宏]或[计数] [命令],它们是链状组合在一起的小构件.单击屏幕是最有效的移动方式,但是在必须执行数千次的大型文本操作任务的子集中可能没有用.

Vim is designed to use small building blocks in repeatable, often complex combinations, to achieve your goal. It is not an inherently efficient process, but for a subset of complex tasks, it's useful. For example, [motion][macro], or [count][command], these are small building blocks combined together in chains. Clicking on the screen is the most efficient movement, but might not be useful in a subset of a large text manipulation task where you have to do it thousands of times.

以下是我通常会记住的所有方式,您看不到这些都是对运动的有效利用,也不是我的认知处理能力. (IDE通过完成下面列出的所有工作来有效地完成工作.)

Here are all the ways I normally use that I can remember, you can see none of these are efficient uses of movement nor my cognitive processing power. (IDEs do things efficiently by taking out all the work listed below).

一旦上线,我个人会使用 f . l ,因为快速扫描显示这是一个独特的字符.或 T .(如果已删除).如果最终有多个.,我将使用; 重复查找,直到找到为止.或者,混搭 w W 直到我接近,因为在涉及标点符号的情况下试图猜测小写的 w 将带您到哪儿基本上是不可能的Vim.

Once on the line I would personally use f.l since a quick scan shows that's a unique character. Or T. if you're past it. If there ends up being more than one . I would use ; to repeat the find until I got to it. Or, mash w or W until I got close, since trying to guess where lowercase w will take you when punctuation is involved is basically impossible in Vim.

如果启用了:set relativenumber,则可以看到它有几行,然后键入n j 到那里,然后键入 f . /kbd>跳到它旁边

If you have :set relativenumber on you can see how many lines away it is, and type nj to go there, then type f. to jump next to it to it

如果启用了:set number,则可以键入(因为您知道行号) 671 G (或: 671 Enter ) f .

If you have :set number on you can type (since you'd know the line number) 671G (or :671Enter) f.

如果您用 m a 标记了该行,则可以跳转到' a 或带有` a 的确切字符(但大多数键盘使`无法到达:(如果它是需要修复的随机跳转.

If you had marked that line with, say ma you could jump to the line with 'a or the exact char with `a (but most keyboards make ` useless to reach :( You probably won't use this one if it's a random look-need-to-fix jump.

如果您已安装 EasyMotion ,则可以输入领导者 领导者 f b subchar 可以直接跳转到

If you have EasyMotion installed you could type leaderleaderfbsubchar to jump right to it

您可以按照@kev的建议进行搜索,并使用 n N 弹跳直到得到为止.如果bark是常见的,但the_lazy_dog是唯一的,则可以执行/dog.b/e Enter (将光标放在比赛结束处),并向Vim神祈祷,您的搜索足够具体,只能进行匹配那条线.那更像是一个有趣的猜谜游戏.

You could search for it as @kev suggests and use nN to bounce around until you get it. If bark is common but the_lazy_dog is unique you could do /dog.b/eEnter (e places cursor at end of match) and pray to the Vim gods that your search was specific enough to only match that line. That's more of a fun guessing game.

根据行在屏幕上的位置,您可以使用(n偏移量) H M L (高中低)靠近它,然后在其中使用 j k .

Depending on where the line is on the screen, you could use (n offset)H, M or L (high middle low) to get closer to it and use jk once there.

或者如果该行的上方/下方有空行,则可以键入超级方便的 {} 来帮助您关闭.

Or if the line has empty lines above / below it you could type the super handy { or } to help you jump close.

或者如果您在gvim中+触控板在附近的笔记本电脑上,也可以使用鼠标.我对此很认真,即使我可能永远也不会做.如果您已经玩了足够多的第一人称射击游戏,那么您的触发手指可能比任何键盘快捷键都更准确,更快捷;)

Or you could use the mouse if you're on a laptop where the trackpad is nearby + in gvim . I'm serious about that, even though I'd probably never do it. if you've played enough first person shooters your trigger finger may be more accurate and fast than any keyboard shortcut ;)

尽管Vim具有疯狂的键盘功能,但并非总是直接或好的方法来执行某些操作,例如非常具体的跳转.您需要保持并不断积累一些技巧,以帮助您四处走动并使用适当的技巧来完成工作.根据我认为最快的速度,我会相当均匀且经常地使用上述所有内容(我使用relativenumber). EasyMotion非常方便,除了执行一次命令的5次击键确实很尴尬并且容易键入错误.

Despite all of Vim'm crazy keyboard power, there is not always a direct nor good way to do something, like very specific jumps. You need to keep and continuously build a bag of tricks to help you move around and use the appropriate ones for the job. I use all of the above fairly evenly and often (I use relativenumber), depending on what I think would be fastest. EasyMotion is pretty handy except that 5 keystrokes to perform one command is really awkward and error prone to type.

因此,在我几年的Vim经验中,我会说没有很好的方法,但是有许多平庸的方法可以合并为一个体面的方法.

So in my humble few years of Vim experience, I'd say there is no good way to do it, but there are a lot of mediocre ways, that you can combine into a decent way.

这篇关于在VIM上达到目标的最有效方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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