Turn: (http://www.cnblogs.com/lijia0511/p/5644566.html)
The learning curve of Vim is quite large (see the learning curve of various text editors), so if you start to see a bunch of Vim's command classifications, you're bound to lose interest in the editor. The following article is translated from "Learn vim progressively", I think this is the best vim for the Novice upgrade tutorial, did not enumerate all the commands, just list the most useful commands. Very good.
Start —————————— body ——————————
Do you want to learn the best text editor vim in human history at the fastest speed? You have to know how to survive vim and then learn tricks at 1.1 o ' all.
Vim The Six billion Dollar editor
Better, Stronger, Faster.
Learn vim and it will be your last text editor to use. There's no better text editor, it's hard to learn, but it's incredibly easy to use.
I suggest the following four steps:
- Survive
- Feel good
- Feel better, stronger, faster
- Use Vim's powers
As you walk through this article, you will become a vim superstar.
Before I start learning, I need to give you some warning:
- Learning Vim is painful at first.
- Take time
- You need to practice constantly, just as you learn an instrument.
- Don't expect you to be able to make vim more efficient than other editors within 3 days.
- In fact, you need 2 weeks of hard practice, not 3 days.
First Level – Survival
- Install Vim
- Start vim
- Don't do anything! Please read first
Once you've installed an editor, you'll want to enter something in it and see what the editor looks like. But Vim is not like this, please follow the following command:
- After starting vim, Vim is in Normal mode.
- Let's go into Insert mode, press the key I. (Chenhao Note: You will see a –insert– word in the lower left corner of vim, indicating that you can enter it as inserted)
- At this point, you can enter the text as if you were using Notepad.
- If you want to return to Normal mode, press theESCkey.
Now, you know how to switch between Insert and Normal mode. Here are some commands that will allow you to survive in Normal mode:
- i→ Insert mode, pressESCback to Normal mode.
- x→ Delete one character of the current cursor.
- :wq→ Save + exit (save:w,:qexit) (Chenhao Note:: W can be followed by file name)
- dd→ Delete the current line and save the deleted line to the Clipboard
- p→ Paste Clipboard
Recommended :
- hjkl(strong example recommends using it to move the cursor, but not necessary) → You can also use the cursor key (←↓↑→). Note:jjust like the down arrow.
- :help <command>→ Displays help for related commands. You can also type without:helpcommand. (Chenhao Note: Exit help requires input: Q)
If you can survive vim and only need the 5 commands above, you will be able to edit the text, and you must practice these commands in a subconscious state. So you can start to step into the second level.
When you enter the second level, you need to say the Normal mode again. In the general editor, when you need to copy a paragraph of text, you need to use aCtrlkey, such as:Ctrl-C. In other words, the CTRL key is like a function key, when you press the function key CTRL, C is not C, and is a command or a fast key, in the normal mode of vim, all keys are function keys . This you need to know.
Mark:
- In the following text, if it isCtrl-λI will write<C-λ>.
- To:start with the command you need to enter a<enter>carriage return, for example-if I write:qthat you want to enter:q<enter>.
Second level – Feels good
The above commands only allow you to survive, now it's time to learn some more commands, here's my advice: (Chenhao Note: All commands need to be used in normal mode, if you don't know what mode you are in now, you can press the ESC key a few times)
-
- Various insertion modes
- a→ Insert after cursor
- o→ Insert a new row after the current line
- O→ Insert a new row before the current line
- cw→ Replace the character from the position of the cursor to the end of a word
-
- A simple Move cursor
- 0→ Digital zero, to the wardrobe
- ^→ To the first position of the bank that is not the blank character (so-called blank character is space, tab, line break, carriage return, etc.)
- $→ To the end of our line
- g_→ To the last position of the bank that is not a blank character.
- /pattern→ Searchpatternfor strings (Chenhao Note: If you search for multiple matches, you can press N to next)
-
- copy/paste (Chenhao Note: p/p can be, p is indicated after the current position, p means before the current position)
- P→ Paste
- yy→ Copy current line of business inddP
-
- Undo/redo
-
- Open/Save/exit/change Files (Buffer)
- :e <path/to/file>→ Open a file
- :w→ Disk
- :saveas <path/to/file>→ Save As<path/to/file>
- :x,ZZor:wq→ Save and exit (:xmeans save only when needed, ZZ does not need to enter a colon and return)
- :q!→ Exit does not save any:qa!files that are being edited by forcibly exiting, even if other files have changed.
- :bnand:bp→ You can open many files at the same time, use these two commands to switch to the next or previous file. (Chenhao Note: I like to use: N to the next file)
Take the time to familiarize yourself with the above commands, and once you've mastered them, you can almost do what other editors are capable of. But until now, you still think it's a bit awkward to use vim, but it doesn't matter, you can step to the third level.
Level three – better, stronger, faster
Congratulations First! You did a good job. We can start something a little more interesting. At the third level, we'll talk about only those commands that are compatible with VI.
Better
Below, let's look at how vim repeats itself:
- .→ (decimal point) You can repeat the last command
- n<command>→ repeat a command n times
Here is an example, find a file you can try the following command:
- 2dd→ Delete 2 rows
- 3p→ Paste text 3 times
- 100idesu [ESC]→ will write down “desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu de su desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu d ESU desu desu desu "
- .→ Repeat the previous command--100 "Desu".
- 3.→ Repeat 3 times "desu" (Note: Not 300, you see, vim how clever AH).
More powerful
You want to make your cursor move more efficiently, you must understand the following commands, never skip .
- nG→ to Nth line (Chenhao Note: Note that the G in the command is uppercase, and I generally use: N to nth rows, such as: 137 To line 137th)
- gg→ to the first line. (Chenhao Note: equivalent to 1G, or: 1)
- G→ to the last line.
- Move by Word:
- w→ To the beginning of the next word.
- e→ To the end of the next word.
> If you think the word is by default, then use lowercase e and W. By default, a word consists of letters, numbers, and underscores (Chenhao Note: program variables)
> If you think the word is delimited by the blank character, then you need to use uppercase E and W. (Chenhao Note: program statement)
Below, let me say the strongest cursor movement:
- %: Match parentheses move, including(,{,[. (Chenhao Note: You need to move the cursor to the parentheses first)
- *and#: matches the current word of the cursor, moves the cursor to the next (or previous) match word (* is next, #is the last one)
Believe me, the above three commands are quite powerful for programmers.
Faster
You must remember to move the cursor, as many commands can be linked to the commands that move the cursor. Many commands can be done as follows:
<start position><command><end position>
For example0y$the command means:
- 0→ first come to the wardrobe
- y→ Start copying from here
- $→ Copy to the last character of the bank
You can enterye, copy from the current position to the last character of the word.
You can also enter ay2/foostring to copy between 2 "foo".
There is still a lot of time that you must press Y to copy, and the following command will be copied:
- dDelete
- v(Visual selection)
- gU(Change capital)
- gu(Variable lowercase)
- Wait a minute
(Chenhao Note: Visual selection is a very interesting command, you can first press V, then move the cursor, you will see the text is selected, and then, you may be d, can also Y, can also be capitalized, etc.) fourth level –VIM Super ability
You just have to master the previous commands and you can use vim very comfortably. But now, we're going to introduce you to the Vim killer feature. The following features are the reason I use vim only.
Move the cursor over the current line:0^$fFtT,;
- 0→ to Wardrobe
- ^→ First non-blank character to the bank
- $→ To the end of the line
- g_→ To the last position of the bank that is not a blank character.
- fa→ To the next character of a, you can also fs to the next character for S.
- t,→ To the first character before a comma. Commas can become other characters.
- 3fa→ Find the third occurrence of a in the current line.
- FandT→ andfthetsame, just the opposite direction.
There is also a very useful command isdt"→ Delete all the content until you encounter double quotes--"。
Regional selection<action>a<object>Or<action>i<object>
In visual mode, these commands are powerful and their command format is
<action>a<object>And<action>i<object>
- The action can be any command, such asd(delete), (ycopy),v(can be selected depending on the mode).
- The object may be:wA word,Wa word separated by a space, a word, aspparagraph. It can also be a special character:"、‘、)、}、]。
Suppose you have a string(map (+) ("foo")). The cursor key is in theo first position.
- vi"→ Will choosefoo.
- va"→ Will choose"foo".
- vi)→ Will choose"foo".
- va)→ Will choose("foo").
- v2i)→ Will Choosemap (+) ("foo")
- v2a)→ Will Choose(map (+) ("foo"))
Block Operation:<C-v>
Block operations, typical operations:0 <C-v> <C-d> I-- [ESC]
- ^→ to Wardrobe
- <C-v>→ Start block operation
- <C-d>→ Move down (you can also use HJKL to move the cursor, or use%, or something else)
- I-- [ESC]→i is inserted, insert "--", press ESC to take effect for each line.
Under Windows Vim, you need to use<C-q>instead<C-v>of copy the<C-v>Clipboard.
Auto Tip:<C-n>And<C-p>
In Insert mode, you can enter the beginning of a word, and then press<C-p>or<C-n>,The auto replenishment function appears……
Macro recording:qaSequence of operationsq,@a,@@
- qaRecord your operation in the registera。
- This@awill replay the macro that was recorded.
- @@is a shortcut key used to replay the latest recorded macro.
Example
In a text that has only one row and this line has only "1", type the following command:
- qaYp<C-a>q→
- qaStart recording
- YpCopy rows.
- <C-a>increased by 1.
- qStop recording.
- @a→ under 1 write down 2
- @@→ Write down 3 on 2 front
- Doing this now[email protected]@creates a new 100 rows and increases the data to 103.
Visualization options:v,V,<C-v>
Earlier, we saw<C-v>The example (under Windows should be <C-q>) that we can usevandV. Once you've been chosen, you can do the following:
- J→ Connect all rows together (into one line)
- <or>→ Left and right indent
- =→ Auto-indent (Chenhao Note: This feature is quite powerful, I love it too)
Add something after all the selected lines:
- <C-v>
- Select the relevant line (you can use or or ...j<C-d>/pattern%)
- $To the end of the line
- A, enter a string, pressESC。
Split screen::splitAndvsplit.
Here are the main commands you can use to help with Vim:help split. You can refer to the previous article of the site Vim split screen.
- :split→ Create split screen (:vsplitcreate vertical split screen)
- <C-w><dir>: dir is the direction, can behjklor one of ←↓↑→, it is used to switch split screen.
- <C-w>_(or<C-w>|): Maximized size (<c-w>| vertical split screen)
- <C-w>+(or<C-w>-): Increase size
Vim Easy to use tutorial