我听说过很多关于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的哪些方式使您的工作效率更高?


当前回答

CTRL + A增加你所站的数字。

其他回答

实际上我总是丢失我的缓冲区,所以我通常复制一行的方式是把它写到一个临时文件,然后在适当的位置读入。

e.g.

Ka(设定标记)

”,。w !T(将标记中的所有内容复制到文件T)

. .移动你的光标。

:.rt(将t读入当前点)。

与使用缓冲区相比,这可能需要更少的击键,更容易跟踪,并且您可以拥有长期存在的粘贴文件。为了速度,我通常用一个字母来命名文件。

快速移动光标的关键原因是,你只需使用搜索函数“/”,如果你在到达你想去的地方之前遇到另一个模式,则使用“n”。

快速剪切和覆盖一行的一部分:

编辑一行时,一个非常常见的任务是从当前光标位置剪切到某个位置,然后覆盖新内容。

可以使用以下命令:

Ct <标识符>为正向切割。

cT<identifier>用于反向切割。

行中要剪切到的字符在哪里。

例子:假设这是你想编辑的行,你的光标在I。

嗨。我是一名程序员,我用Python和R编程。

你想切到:,然后用I am a programmer覆盖,你输入:ct:,然后输入I am a programmer。这将导致:你好。我是程序员:Python和R。

快速删除一行的部分:

就像上面的命令一样,从当前光标位置删除内容,直到'identifier'

Dt <identifier>用于前向删除

dT<identifier>用于反向删除

希望这对你也有用。

提高编辑速度的第三个标准是所需的击键次数。我得说这比你的其他两个更重要。在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使我更有效率?”,我希望答案是“高效”。

特别是对于复制/剪切和粘贴,使用可视化模式更容易适应其他编辑器。我通常复制粘贴的方法是

Esc - exit Insert mode (skip if you are already in Normal mode) v - turn on visual mode move about the file to select the text you want - visual mode will show you what characters are selected. For a few words w, e and b are useful (move to start of next word, end of next word and start of this/previous word respectively). d - cut the text (use y if you want to copy the text) move about to where you want the text to go p - paste (this pastes after the current character, P pastes before the current character.

同样有用的是使用V进入视觉模式(行),它会自动选择整行,无论光标在哪里。

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.

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