我听说过很多关于Vim的事,包括优点和缺点。 (作为一名开发人员)使用Vim确实应该比使用其他任何编辑器都要快。 我用Vim来做一些基本的事情,我用Vim最多只能减少10倍的效率。

当你谈论速度时,只有两件事你应该关心(你可能不够关心,但你应该关心):

左右交替使用的 用手是最快的方法 键盘。 永远不要碰鼠标 第二种方法是尽可能快。 你要花很长时间才能移动你的手, 抓住鼠标,移动它,把它带来 回到键盘上(你经常这样做 看看键盘,确保你 将你的手正确地回到正确的位置)

下面的两个例子说明了为什么我使用Vim效率低得多。

复制/剪切和粘贴。我一直都这么做。在所有当代编辑器中,你用左手按Shift键,用右手移动光标来选择文本。然后按Ctrl+C复制,移动光标,按Ctrl+V粘贴。

Vim的情况很糟糕:

Yy复制一行(你几乎不需要整行!) [number xx]yy复制xx行到缓冲区。但你永远不知道你是否选择了你想要的。我经常要做[number xx]dd然后u来撤销!

另一个例子吗?搜索和替换。

在PSPad中:按Ctrl+f,然后输入你想要搜索的内容,然后按Enter。 在Vim: /中,然后输入你想要搜索的内容,然后如果有一些特殊字符,在每个特殊字符前放\,然后按Enter。

Vim的一切都是这样的:似乎我不知道如何正确处理它。

注:我已经读了Vim小抄:)

我的问题是:

与当代编辑器相比,您使用Vim的哪些方式使您的工作效率更高?


当前回答

花30分钟做vim教程(在终端运行vimtutor而不是vim)。您将学习基本的动作和一些击键,这将使您使用vim至少与使用之前使用的文本编辑器一样高效。在那之后,好吧,再读一遍吉姆·丹尼斯的回答:)

其他回答

你说的是文本选择和复制,我认为你应该看看Vim可视模式。

在可视模式下,您可以使用Vim命令选择文本,然后可以对所选内容做任何您想做的事情。

考虑以下常见场景:

您需要选择到下一个匹配的括号。

你可以这样做:

如果光标位于开始/结束括号上,则为V % 如果光标位于圆括号块内,则返回Vib

你想要在引号之间选择文本:

Vi”表示双引号 Vi '表示单引号

你想要选择一个大括号块(在c风格语言中非常常见):

viB vi {

你想要选择整个文件:

ggVG

可视化块选择是另一个非常有用的功能,它允许你选择一个矩形区域的文本,你只需要按Ctrl-V来启动它,然后选择你想要的文本块,并执行任何类型的操作,如拉拽,删除,粘贴,编辑等。编辑面向列的文本非常棒。

<Ctrl> + W, V垂直分割屏幕 <Ctrl> + W, W在窗口之间移动

!python % [args]来运行我在此窗口中编辑的脚本

ZF在可视模式下折叠任意线条

提高编辑速度的第三个标准是所需的击键次数。我得说这比你的其他两个更重要。在vim中,几乎所有的操作都比我熟悉的任何其他编辑器需要更少的按键。

You mention that you are having trouble with cut & paste, but it sounds like you need more experience with general motion commands in vim. yank 3 words: y3w yank from the cursor to the next semi-colon: yf; yank to the next occurrence of your most recent search: yn All of those are much faster than trying to navigate with a mouse while holding down a modifier key. Also, as seen in some of the examples in CMS's response, vim's motion commands are highly optimized for efficient navigation in C and C++ source code.

至于“如何使用vim使我更有效率?”,我希望答案是“高效”。

在代码中插入文本:

ctrl + v, (selecting text on multiple lines), I, (type something I want), ESC

记录一个宏来编辑文本并运行N次:

q, a (or some other letter), (do the things I want to record), q, ESC,
(type N, as in the number of times I want to run the macro), @, a

In addition to the great reply about grokking vi, it should be noted that vim does add some very vi-like features that make using vi commands nicer. The one that comes to mind first are text objects: instead of {!}fmt to reformat the current paragraph, !apfmt does the same. It works by first specifying that we want to select a text object, which is the current paragraph. Similar, to change the current string literal (foo to bar for an example), instead of T"ct"bar (move to just after the previous ", change until just before the next ", insert bar), you can say ci"bar: change inside (innermost) quotes, inserting bar.

从文本对象而不是移动命令的角度思考是非常不错的。