Learn Vim Progressively——level1&level2

You want to teach yourself vim (the best text editor known to human kind) in the fastest way possible. This is my way of doing it. You start by learning the minimal to survive, then you integrate all the tricks slowly.

你想要用最快的方式来自学vim(对人类来说最好的文本编辑器)。这是我做到的方式。首先,你通过学习最基本的方式来生存下来,然后慢慢地扩展所有的技巧。


Vim the Six Billion Dollar editor

Better, Stronger, Faster.


Learn vim and it will be your last text editor. There isn’t any better text editor that I know of. It is hard to learn, but incredible

to use.

学习vim,它将成为你最后一个文本编辑器。据我所知,还没有一种编辑器比它还要好用。尽管学习它是很困难的,但使用起来是难以置信的。


I suggest you teach yourself Vim in 4 steps:

1. Survive

2. Feel comfortable

3. Feel Better, Stronger, Faster

4. Use superpowers of vim

我建议你从以下四步来自学:

1.生存

2.感觉很舒服

3.感觉很好,很强大,很迅速

4.使用vim的超能力

 

By the end of this journey, you’ll become a vim superstar.

But before we start, just a warning. Learning vim will be painful at first. It will take time. It will be a lot like playing a musical instrument. Don’t expect to be more efficient with vim than with another editor in less than 3 days. In fact it will certainly take 2 weeks instead of 3 days.

在这场学习的旅程末,你将成为一个vim超能者。

但是在我们开始旅程前,做一个小小的警告。刚开始学习vim是痛苦的,这将会持续一段时间,这和刚开始学一门乐器有很大的相似之处。别想着能够在3天之内就使用vim比其他编辑器要高效。事实上这个时间可能要花费两周而不是3天!



1st Level – Survive

1. Install vim

2. Launch vim

3. DO NOTHING! Read.

等级1:生存

1)安装vim

2)启动vim

3)除了继续读,什么也不要做


In a standard editor, typing on the keyboard is enough to write something and see it on the screen. Not this time. Vim is in Normalmode.

Let’s go to Insert mode. Type the letter i.

对一个标准的编辑器,准备好敲击键盘已经足够用来写东西并且能够在屏幕上看到。这次可不行。Vim正处在normal模式。让我们进入insert模式,请敲击字母i。

 

You should feel a bit better. You can type letters like in a standard editor. To get back to Normal mode just press the ESC key.

现在你应该感到好点了。你可以像用标准编辑器那样敲击键盘打字了。如果想回到normal模式,请按ESC


You now know how to switch between Insert and Normal mode. And now, here are the commands that you need in order to survive inNormal mode:

· i → Insert mode. Type ESC to return to Normal mode.

· x → Delete the char under the cursor

· :wq → Save and Quit (:w save, :q quit)

· dd → Delete (and copy) the current line

· p → Paste

现在你知道如何在insert模式与normal模式之间切换了。接下来,你要学会能够在normal模式下生存的命令:

i->insert模式。按esc返回normal模式

x->删除光标所在处的字符

:wq->保存并退出(:w 保存,:q 退出)

dd->删除(并复制)当前行 (译者:删除并复制当然就是剪切)

p->粘贴


Recommended:

· hjkl (highly recommended but not mandatory) → basic cursor move (←↓↑→). Hint: j looks like a down arrow.

· :help <command> → Show help about <command>. You can use :help without a <command> to get general help.

建议:

hjkl(极力推荐但并不是必须)作为光标移动左下上右->基本光标移动(←↓↑→).小提示:j看起来像一个向下的箭头

:help <command>->打开<command>的帮助.你可以使用:help加一个<command>来获得一个大概的帮助。

  

Only 5 commands. That is all you need to get started. Once these command start to become natural (maybe after a day or so), you should move on to level 2.

只有5个命令。这是你刚开始需要掌握的全部。一旦你使用这些命令变得很自然(可能一天或是更久),你应该进入到级别2了。


But first, just a little remark about Normal mode. In standard editors, to copy you have to use the Ctrl key (Ctrl-c generally). In fact, when you press Ctrl, it is as if all of your keys change meaning. Using vim in normal mode is a bit like having the editor automatically press the Ctrl key for you.

但是首先,关于normal模式有一个小小的提示(注意)。在标准编辑器中,你可是使用Ctrl键(通常是Ctrl-c)来复制。事实上,当你按下Ctrl,它像是在表明,你的所有的按键都改变意思了(译者:激活辅助键)。在normal模式下使用vim有点像编辑器自动按下ctrl键来帮助你(译者:每个按钮都有它的特殊含义,有点像ctrl+其他键来完成辅助性的任务,而你却不需要自己按Ctrl)


A last word about notations:

· instead of writing Ctrl-λ, I’ll write <C-λ>.

· commands starting with : end with <enter>. For example, when I write :q, I mean :q<enter>.

关于表示法的最后一点补充:

我将使用<C-λ>, 而不是Ctrl-λ

命令以:开始,以<enter>结束。例如:当我写:q,我要表达的意思是:q<enter>.


2nd Level – Feel comfortable

You know the commands required for survival. It’s time to learn a few more commands. These are my suggestions:

级别二:感到舒服

你已经知道满足生存需求的命令,是时候学习更多的命令了。下面是我的建议:


1. 

Insert mode variations:

· a → insert after the cursor

· o → insert a new line after the current one

· O → insert a new line before the current one

· cw → replace from the cursor to the end of the word

不同的插入模式:

a->在光标后插入

o->在当前行的下一行插入

O->在当前行的上一行插入

cw->从光标到单词末尾作替换(译者:即删除从光标到光标所在单词末尾的字符,并进入insert模式,dw只是删除字符,不进入insert模式)

 

2. 

Basic moves

· 0 → go to the first column

· ^ → go to the first non-blank character of the line

· $ → go to the end of line

· g_ → go to the last non-blank character of line

· /pattern → search for pattern

基本移动

0->移动到行首

^->移动到该行第一个非空白符的位置

$->移动到行尾

g_->移动到该行最后一个非空白符的位置

/pattern->搜索字符串pattern

3. 

Copy/Paste

· P → paste before, remember p is paste after current position.

· yy → copy the current line, easier but equivalent to ddp

复制/粘贴

P->粘贴到当前位置之前,记住p是粘贴到当前位置之后

yy->复制当前行,功能和ddp相似(译者:ddp是剪切后的粘贴,dd剪切一行,p粘贴)。

4. 

Undo/Redo

· u → undo

· <C-r> → redo

撤销/恢复:

u->撤销

<C-r>恢复


5. 

Load/Save/Quit/Change File (Buffer)

· :e <path/to/file> → open

· :w → save

· :saveas <path/to/file> → save to <path/to/file>

· :xZZ or :wq → save and quit (:x only save if necessary)

· :q! → quit without saving, also: :qa! to quit even if there are modified hidden buffers.

· :bn (resp. :bp) → show next (resp. previous) file (buffer)

载入/保存/退出/修改文件

:e<path/to/file>->打开该文件

:w ->保存

:saveas<path/to/file>->保存到<path/to/file>

:x,zz or :wq->保存并退出(译者::x与:wq的区别 x只有在文件发生修改时才写入保存,并修改文件最后修改时间,:wq不论文件是否发生修改都写入保存,并修改文件最后修改时间)

:q!->退出但不保存,qa!退出即使缓冲区中有修改

:bn(:bp)->打开缓冲区中的下一个(上一个)文件


Take the time to learn all of these command. Once done, you should be able to do every thing you are able to do in other editors. You may still feel a bit awkward. But follow me to the next level and you’ll see why vim is worth the extra work.

花一段时间学会这些命令,一旦做到了,你应该就能够做到在其他编辑器中能够做到的所有的事情了。也许你仍然觉得有点笨拙不适应。不要急,跟随我学习下一个等级,你会看到学习vim为什么会比其他编辑器更值得。










文章原文来自:http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/#navigation


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。