Vim Editor's use introduction

Source: Internet
Author: User
Tags lowercase
Want to learn the best text editor vim in human history at the fastest speed? First you have to know how to survive in Vim, and then learn all kinds of tricks at 1.1 o '-point.




Vim The Six billion Dollar editor




The code is as follows

Better, stronger, faster.




Learn vim and it will become the last text editor you use. There is no better text editor than this, it is very difficult to learn, but incredibly easy to use.




I recommend the following four steps:





    1. Survive

    2. Feel good

    3. Feel better, stronger, faster

    4. Using Vim's abilities




When you walk through this article, you will become a vim of superstar.




Before I begin to study, I need to give you some warning:





    • Learning Vim is painful at first.

    • Take time

    • You need to keep practicing, just as you learn an instrument.

    • Don't expect you to practice vim more efficiently than other editors in 3 days.

    • In fact, you need 2 weeks of hard practice, not 3 days.




First Level – Survival





    1. Install Vim

    2. Start vim

    3. Don't do anything! Please read it first




When you install 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 instructions below:





    • When you start Vim, Vim is in Normal mode.

    • Let's go into Insert mode, press the key. (Chenhao Note: You'll see Vim has a –insert– typeface in the lower left corner, indicating that you can enter it in the form of an insert)

    • At this point, you can enter text, just as you would with 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:




The code is as follows


  • i→ Insert mode, press ESC to return to Normal mode.

  • x→ deletes one character from the current cursor.

  • : wq→ Save + exit (: W disk,: Q exit) (Chenhao Note:: W can be followed with filename)

  • dd→ deletes the current line and saves the deleted row to the Clipboard

  • p→ paste Clipboard

Recommended :


  • HJKL (strong example recommended to use its mobile cursor, but not required) → You can also use the cursor key (←↓↑→). Note: J is like a down arrow.

  • : help→ displays Help for related commands. You can also enter: Help without command. (Chenhao Note: Exit help requires input: Q)




You can survive in vim with only the above 5 commands, you can edit the text, you must make these commands into a subconscious state. So you can begin to step up to the second level.




When it is, when you enter the second level, you need to say the Normal mode. Under the general editor, when you need to copy a text, you need to use the CTRL key, such as: Ctrl-c. That is, the CTRL key is like a function key, when you press the function key CTRL, C is not in 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 is ctrl-λ I will write

    • To: Start the command you need to enter a carriage return, for example-if I write: Q is to say you want to enter: Q.




Second level – Feel good




The above commands will only allow you to survive, now is the time to learn some more commands, here are my suggestions: (Chenhao Note: All commands need to be used in normal mode, if you do not know what the current mode, you are crazy press the ESC key several times)





  1. Various insert modes

    The code is as follows


    • a→ inserts after the cursor

    • o→ inserts a new row after the current line

    • o→ inserts a new row before the current line

    • Cw→ replaces characters from the position of the cursor to the end of a word

  2. Simple Move Cursor

    The code is as follows


    • 0→ Digit Zero, to the wardrobe

    • ^→ to the bank the first is not a blank character position (the so-called blank character is a space, tab, line, enter, etc.)

    • $→ to the bank at the end of the line

    • g_→ to the last position of the bank that is not a blank character.

    • /pattern→ Search for pattern strings (Chenhao Note: If you search for multiple matches, press N to the Next button)

  3. copy/paste (Chenhao Note: p/p All can, p is to indicate that after the current position, p means before the current position)

    The code is as follows


    • p→ paste

    • yy→ copy Current line of business in DdP

  4. Undo/redo

    The code is as follows


    • U→undo

    • →redo

  5. Open/Save/exit/change Files (Buffer)

    The code is as follows


    • : e→ Open a file

    • : w→ Disk

    • : saveas→ Save As

    • : X, ZZ or: wq→ Save and exit (: X means save only when needed, ZZ does not need to enter a colon and returns)

    • : q! → Exit not Save: qa! Forcibly exits all the files being edited, even if other files have changed.

    • : Bn and: bp→ You can open a lot of files at the same time, using these two commands to switch between 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're almost ready to do what other editors are capable of. But until now, you still think it's a bit clumsy to use vim, but it doesn't matter, you can step up to the third level.




Level three – better, stronger, faster




Congratulations to you first! You did a good job. We can start something even more interesting. At the third level, we only talk about those commands that are compatible with VI.




Better




Below, let's look at how vim repeats itself:





    1. . → (decimal point) You can repeat the last command

    2. n→ repeats a command n times




Here is an example to find a file you can try the following command:




The code is as follows


  • 2dd→ Delete 2 lines

  • 3p→ paste 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 "

  • . → Repeat the previous command--100 "Desu".

  • 3.→ repeat 3 times "desu" (Note: Not 300, you see, vim how clever AH).




More powerful




If you want to make your cursor move more efficiently, you must understand the commands below and don't skip it.





    1. 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)

    2. gg → to the first line. (Chenhao Note: equivalent to 1G, or: 1)

    3. g → to the last line.

    4. move by word:

        code is as follows


      1. w → to the beginning of the next word. The

      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 (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)




Next, let me say the strongest cursor movement:




The code is as follows


  • %: match bracket 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) matching word (* is next, #是上一个)




Believe me, these three commands are quite powerful for programmers.




Faster




You must remember that the cursor moves, because many commands can be connected to the commands that move the cursor. Many commands can be done as follows:







For example the 0y$ command means:





    • 0→ first to the wardrobe.

    • y→ start copying from here.

    • $→ copy to the last character of the bank




You can enter ye and copy the last character of the word from the current position.




You can also enter a y2/foo to copy the string between 2 "foo".




There is still a lot of time not necessarily you have to press Y to copy, the following command will be copied:





    • D (Delete)

    • V (visual selection)

    • GU (uppercase)

    • Gu (change lowercase)

    • Wait a minute




(Chenhao Note: Visual selection is a very interesting command, you can press V, then move the cursor, you will see the text is selected, and then, you may be d, Y, can also be capitalized, etc.)




Level fourth –vim Super power




You just need to master the previous commands and you'll be comfortable using VIM. But, now, we're going to introduce you to the Vim killer feature. The following features are the only reason I use VIM.




Move the cursor over the current line: 0 ^ $ f f T,;




The code is as follows


  • 0→ to the wardrobe.

  • ^→ The first non-blank character to 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 at a, you can also fs to the next character of S.

  • t,→ to the first character before the 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 in the opposite direction.




Another useful command is dt "→ delete all content until it encounters double quotes--".




Area selection A or I




In visual mode, these commands are powerful, and their commands are formatted as




A and I





    • The action can be any command, such as D (delete), Y (copy), V (can be viewed as the mode selection).

    • Object may be: W A word, w a word separated by a space, s a word, p a paragraph. can also be a special character: ", ',",},].




Suppose you have a string (map (+) ("foo")). And the cursor key is in the position of the first O.




The code is as follows


  • VI "→ Will choose Foo.

  • VA "→ will select" foo ".

  • VI) → will select "foo".

  • VA) → will Select ("foo").

  • v2i) → select map (+) ("foo")

  • V2A) → Select (Map (+) ("foo")







Block action:




Block operation, typical operation: 0i--[ESC]





    • ^→ to the wardrobe.

    • → Start block operation

    • → Move down (you can also use HJKL to move the cursor, or use%, or whatever)

    • i--[Esc]→i is INSERT, insert "--", press ESC to take effect for each row.







Under Windows Vim, you need to use the Clipboard instead of the copy.




Auto Tip: and




In Insert mode, you can enter the beginning of a word, and then press or, the automatic completion function appears ...







Macro recording: QA operation sequence Q, @a, @@





    • QA Records your operations in register a.

    • So @a will replay the recorded macro.

    • @@ 是 A shortcut key used to replay the most recently recorded macros.




The code is as follows

Example

In a text that has only one row and only "1" in this line, type the following command:


  • qaypq→

    • QA starts recording

    • Yp copy rows.

    • increased by 1.

    • Q Stop Recording.

  • @a→ under 1, write down 2.

  • @@→ write down 3 on the 2 front.

  • Doing 100@@ 会 creates a new 100 line and increases the data to 103.







Visual selection: V,v,




Before we see the example (which should be in Windows), 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

    • =→ automatically indent (Chenhao Note: This function is quite powerful, I like it too)







Add something to all the selected lines:






    • Select the related line (use J or/pattern or% etc. ...)

    • $ 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 with vim: Help split. You can refer to this site before an article vim split screen.




The code is as follows


  • : split→ Create a split screen (: Vsplit Create a vertical split screen)

  • : dir is the direction, which can be one of the HJKL or ←↓↑→, which is used to toggle the split screen.

  • _ (or |) : Maximum Size (| vertical split screen)

  • + (or-): Increase the size







Conclusion





    • Above is the author's most commonly used 90% command.

    • I suggest you learn 1 to 2 new commands every day.

    • After three weeks, you'll feel vim's strength.





    • Sometimes, learning vim is like dying to memorize something.

    • Fortunately, VIM has a lot of good tools and good documentation.

    • Run Vimtutor until you are familiar with those basic commands.

    • One of the online help documents that you should read carefully is: Helps Usr_02.txt.

    • You will learn many other functions such as!, catalogs, registers, plug-ins, and so on.




Learning Vim is like learning to play the piano, once learned, the benefit is endless.
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.