Vim advanced Concise Manual (2)

Source: Internet
Author: User
Level 3-better, stronger, and faster congratulations! You did a good job. We can start something more interesting. In Level 3, we only talk about commands that are compatible with vi. Better, let's take a look at how vim repeats itself:. → (decimal point) can repeat the previous command Ncommand → repeat a command N times. below is

Level 3-better, stronger, and faster congratulations! You did a good job. We can start something more interesting. In Level 3, we only talk about commands that are compatible with vi. Better, let's take a look at how vim repeats itself:. → (decimal point) can repeat the previous command Ncommand → repeat a command N times. below is

Level 3-better, stronger, and faster

Congratulations! You did a good job. We can start something more interesting. In Level 3, we only talk about commands that are compatible with vi.

Better

Next, let's take a look at how vim repeats itself:

  1. .→ (Decimal point) The last command can be repeated
  2. N→ Repeat a command N times

The following is an example. To open a file, try the following command:

  • 2dd→ Delete 2 rows
  • 3p→ Paste the text three times
  • 100idesu [ESC]→ Write "desu desu desu"
  • .→ Repeat the previous command -- 100 "desu".
  • 3.→ Repeat "desu" three times (Note: It's not 300. You see, how clever VIM is ).
Stronger

To make your cursor move more efficiently, you must understand the following commands and never skip them.

  1. NG→ To line N (Chen Hao Note: note that G in the command is capitalized, And I generally use: N to line N, for example, lines 137 to 137th)
  2. gg→ To the first line. (Chen Hao Note: equivalent to 1G, or: 1)
  3. G→ To the last line.
  4. Move by word:
    1. w→ Start with the next word.
    2. e→ To the end of the next word.

    > If you think the word is in the default format, use the lower case e and w. By default, a word consists of letters, numbers, and underscores (Chen Hao Note: program variables)

    > If you think words are separated by blank characters, you need to use uppercase E and W. (Chen Hao Note: program statements)

Next, let me talk about the strongest cursor movement:

  • %: The matching brackets are moved, including(,{,[. (Chen Hao Note: you need to move the cursor first to brackets)
  • *And#: Match the current word of the cursor, move the cursor to the next (or the previous) match the word (* is the next, # Is the previous)

Believe me, the above three commands are quite powerful for programmers.

Faster

You must remember the movement of the cursor, because many commands can be linked with the commands that move the cursor. Many commands can be used as follows:

For example0y$Command means:

  • 0→ First come to the line Header
  • y→ Copy from here
  • $→ Copy to the last character of the row

You can enteryeFrom the current position to the last character of the word.

You can also entery2/fooTo copy the strings between two "foo.

There is still a lot of time and you may have to press y to copy the file. The following command will also be copied:

  • d(Delete)
  • v(Visualized selection)
  • gU(Change to uppercase)
  • gu(Small write)
  • And so on.

(Note: Visual selection is an interesting command. You can press v first and move the cursor to see the selected text. Then, you may d or y, can also be changed to uppercase)

Level 4-Vim super power

You only need to master the previous commands, and you can use VIM comfortably. But now we will introduce you to the VIM killer feature. The following are the reasons why I only use vim.

Move the cursor over the current row: 0 ^ $ f F t T , ;
  • 0→ To the line Header
  • ^→ The first non-blank character to the line
  • $→ End of line
  • g_→ The last line is not the position of the blank character.
  • fa→ To the next character with a, you can also use fs to the next character with s.
  • t,→ The first character before the comma. A comma can be another character.
  • 3fa→ Search for the third a in the current row.
  • FAndT→ AndfAndtSame, but in the opposite direction.

Another useful command is:dt"→ Delete all content until double quotation marks --"。

Region selection AOrI

In visual mode, these commands are powerful in the format

A AndI

  • Action can be any command, suchd(Delete ),y(Copy ),v(You can select the mode as needed ).
  • The object may be:wOne word,WA word separated by spaces,sOne sentence,pA paragraph. It can also be a special character:"、 '、 )、 }、 ]。

Suppose you have a string(map (+) ("foo")). The cursor key is in the firsto .

  • vi"→ Selectfoo.
  • va"→ Select"foo".
  • vi)→ Select"foo".
  • va)→ Select("foo").
  • v2i)→ Selectmap (+) ("foo")
  • v2a)→ Select(map (+) ("foo"))

Block operation:

Block operations, typical operations:0 I--[ESC]

  • ^→ To the line Header
  • → Start block Operation
  • → Move down (you can also use hjkl to move the cursor, use %, or something else)
  • I-- [ESC]→ I is insert, insert"--", Press ESC to take effect for each row.

For vim in Windows, you need to use Instead , Is to copy the clipboard.

Automatic prompt: And

In Insert mode, you can enter the beginning of a word, and then press Or , The auto-completion function appears ......

Macro recording:qaOperation Sequenceq,@a,@@
  • qaRecord your operations in the registera。
  • Therefore@aMacro that will replay the recording.
  • @@Is a shortcut key used to replay the macro of the latest recording.

Example

In the text with only one line and only one line, type the following command:

  • qa Yp q →
    • qaStart recording
    • YpCopy row. // Y copy row p Paste
    • Add 1.
    • qStop recording.
  • @a→ Write down 2 below 1
  • @@→ Write 3 in front of 2
  • Now do100@@A new 100 row is created and the data is increased to 103.

Visual selection:v,V,

We can see that (In Windows, it should be ), We can use vAnd V. Once selected, you can do the following:

  • J→ Connect all rows (into one row)
  • <Or>→ Left and right indent
  • =→ Auto indent (note: this function is quite powerful and I like it too much)

Add something after all selected rows:

  • Select related rows (you can usejOr Or/patternOr%......)
  • $To the end of the line
  • A, Input string, pressESC。 (I add something before the row. A is after the row.)

Split screen::splitAndvsplit.

The following are the main Commands. You can use VIM's help.:help split. You can refer to the previous article VIM split screen.

  • :split→ Create a split screen (:vsplitCreate a Vertical Split screen)
  • : Dir is the direction, which can be hjklOr one of them, which is used to switch the split screen.
  • _ (Or | ): Maximize the size ( | Vertical Split screen)
  • + (Or - ): Increase the size.

Learning vim is just like learning to play the piano.

---------- Text ended ----------

This is an editor that you don't need to use a mouse or a keypad. You only need to use a keypad to complete text editing for many complex functions. Otherwise, Visual Studio won't have the vim plug-in.

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.