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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章