Vim Training Guide (Turn)

Source: Internet
Author: User

Turn from the ordinary World: http://www.ccvita.com/

Objective
See this article today, resonance very much. It divides vim into 4 levels, and at present I am proficient in using the previous level Three command, in the cultivation habits of the fourth level. It's exactly the process I've been using vim for a year. So no matter how I want to reprint this article. Translated from "Learn vim progressively", the original Chinese translation from the "Concise Vim training strategy." I did a part of the typesetting work, and the text was truncated and all the pictures were localized.

Vim's learning curve is quite large, so if you're starting to see a bunch of Vim's command classifications, you're bound to lose interest in the editor. The following article 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.

Better, Stronger, Faster.

Body
Do you want to learn the best text editor vim in human history at the fastest speed? You need to know how to survive vim and then learn a variety of uses at 1.1. 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:

  1. Survive
  2. Feel good
  3. Feel better, stronger, faster
  4. Use Vim's powers

When you finish this article, you will become a VIM superstar, before you begin to learn, 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 and start vim, don't do anything! please read it 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.
  • At this point, you can enter the text as if you were using Notepad.
  • If you want to return to Normal mode, press the ESC key.


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, press ESC to return to Normal mode.
  • x→ Delete the character of the current cursor.
  • : wq→ disk + exit (: W disk, : Q exit)
  • dd→ Delete the current row and save the deleted row to the Clipboard
  • p→ pasting the Clipboard


Recommended :

  • HJKL (strong example recommends using it to move the cursor, but not necessary) → You can also use the cursor key (←↓↑→). Note: J is like the down arrow.
  • : Help <command>→ displays assistance with related commands. You can also enter : Help instead of the command.


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 the Ctrl key, 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.
Tags :

  • In the following text, if it is ctrl-λ I will write <c-λ>.
  • To : Start the command you need to input <enter> Enter, for example-if I write : Q that is to say you want to input : q<enter>.

Second level feels good
The above commands only let you survive, now is the time to learn some more commands, here are my suggestions:

  1. Various insertion modes
    • a→ inserted after the cursor
    • o→ inserts a new row after the current row
    • o→ inserting a new row before the current line
    • Cw→ replaces characters from the position of the cursor to the end of a word
  2. A simple Move cursor
    • 0→ Digit Zero, to the wardrobe
    • ^→ to the first position of the bank that is not the blank character (the so-called blank character is a 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→ searching for pattern strings
  3. Copy/paste
    • p→ paste
    • yy→ copy Current line of business in DdP
  4. Undo/redo
    • U→undo
    • <c-r>→redo
  5. Open/Save/exit/change Files (Buffer)
    • : E <path/to/file>→ Open a file
    • : w→ Disk
    • : SaveAs <path/to/file>→ saved as <path/to/file>
    • : x, zz or : wq→ Save and exit (: X means save only when needed, ZZ does not need to enter a colon and return)
    • : q! → Exit does not save : qa! forcibly quits all files being edited, even if other files have changed.
    • : Bn and : bp→ You can open many files at the same time, use these two commands to switch to the next or previous 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.

The third level is 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.

  1. Better
    Below, let's look at how vim repeats itself:
    1. . → (decimal point) You can repeat the last command
    2. 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→ pasting text 3 times
    • 100idesu [ESC] → 会写下 “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 desu desu desu "
    • . → Repeat the previous command--100 "Desu".
    • 3.→ repeated 3 times "desu" (Note: Not 300, you see, vim how clever AH).
  2. more powerful
    You want to make your cursor move more efficiently, you must understand the following commands,Please don't skip it.
    1. ng→ to nth row.
    2. gg→ to the first line.
    3. g→ to the last line.
    4. Move by Word:
      1. w→ to the beginning of the next word.
      2. 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 (note: program variables)
      > If you think the word is delimited by the blank character, then you need to use uppercase E and W. (Note: program statement)

    Below, let me say the strongest cursor movement:
    • %: Match parentheses move, including (, {, [.
    • * and #: match the current word of the cursor, move the cursor to the next (or previous) match word (* is next, #是上一个)

    Believe me, the above three commands are quite powerful for programmers.
  3. 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 example , the 0y$ command means:
    • 0→ to the wardrobe first.
    • y→ start copying from here
    • $→ copy to the last character of the bank

    You can enter ye to copy from the current position to the last character of the word.
    You can also enter a y2/foo to copy the string between 2 "foo".
    There is still a lot of time that you must press Y to copy, and the following command will be copied:
    • D (Delete)
    • V (visual selection)
    • GU (variable capitalization)
    • GU (variable lowercase)
    • Wait a minute

Fourth level Vim Super power
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 ^ $ F F t t , ;
    • 0→ to Wardrobe
    • ^→ to the first non-blank character of the bank
    • $→ to end of 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→ finds the third occurrence of a in the current row.
    • F and t→ and F and T are just the opposite direction.

    And there's a very useful command.DT "→ delete all contents until double quotes are encountered-- ".
  • 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 as D (delete), y (copy), V (selectable depending on the mode).
    • The object may be: w A word, w A word separated by a space, s a sentence, p a paragraph. can also be a special character:", '," ), }, ].

    Suppose you have a string (map (+) ("foo")). The cursor key is positioned at the first O.
    • vi " → will select  foo.
    • va " → will select  " foo ".
    • vi)  → will select  
    • va)  → will select
    • v2i)  → will select  map (+) ("foo")
    • v2a)  → will select  
  • <C-V>
    Block operation, typical operation:  0 <C-v> <C-d> i--[ESC]
    • ^ → to wardrobe
    • <c-v& gt; → Start block action
    • <c-d> → Move Down (you can also use HJKL to move the cursor, or use%, or something else)
    • i--[esc] →i is insert, insert ' --' and press ESC to take effect for each row.

    under Windows Vim, you need to use   <c-q>  instead of  <C-V>&NBSP; <c-v>  is a copy of the Clipboard.
  • Auto Tip: <C-n> and <C-p>
    In Insert mode, you can enter the beginning of a word, then press <C-p> or <C-N>, and the auto-fill function will appear ...
  • macro recording: QA operation sequence q, @a , @@
    • QA Records your operation in register a.
    • So @a will replay the macro that was recorded.
    • @@ 是 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→
      • QA starts recording
      • Yp copy rows.
      • <C-a> increased by 1.
      • Q Stop Recording.
    • @a→ below 1, write down 2.
    • @@→ on 2 front write down 3
    • Now do [email protected]@ will create a new 100 rows and add data to 103.
  • Visual selection: V,V,<C-v>
    Ahead, we saw theExamples of <C-v> (under Windows should be <C-q>), we can use V and v. Once you've been chosen, you can do the following:
    • j→ to connect all the rows (into one line)
    • < or >→ indent around
    • =→ Auto-indent

    Add something after all the selected lines:
    • <C-V>
    • Select related rows (use  j   or  <c-d>  or  /pattern  or  < Span class= "Codefont" >%  ...)
    • $  to the end of the line
    • a, enter the string, press  esc.
  • Split screen: : Split and vsplit.
    Here are the main commands that you can use to help with Vim : Helping split. You can refer to the VIM split screen.
    • : split→ Create split screen (: vsplit Create vertical split screen)
    • <C-w><dir>: dir is the direction, can be one of hjkl or ←↓↑→, 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

Conclusion

      • Above are the 90% most commonly used commands by the author.
      • I suggest you learn 1 to 2 new commands every day.
      • After three weeks, you will feel the power of vim.
      • Sometimes, learning vim is like dying with something.
      • Fortunately, VIM has a lot of great tools and excellent documentation.
      • Run Vimtutor until you are familiar with the basic commands.
      • What you should read carefully in its online help documentation is: "Helping usr_02.txt."
      • You will learn many other functions such as!, directories, registers, plugins, etc.

Vim Training Guide (Turn)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.