[Reprinted] Vim concise tutorial [CoolShell]

Source: Internet
Author: User

 
  1. Do nothing!Read

    NormalMode.
  • InsertMode. Press I. (Chen Hao Note: you will see the "-insert-" in the lower-left corner of vim, indicating that you can insert it)
  • NormalMode. PressESCKey.

InsertAndNormalSwitched. Below are some commands for youNormalMode:

I→ InsertMode, press ESCBack NormalMode.
  • X→ Delete a character of the current cursor.
  • : Wq→ Save disk + exit (:wStorage,:qExit) (Chen Hao note: the file name can be followed after w)
  • Dd→ Delete the current row and save the row to the clipboard.
  • P→ Paste clipboard
  • Recommendation:

      Hjkl(For strong examples, we recommend that you move the cursor, but it is not required.) → you can also use the cursor key. Note: jJust like the down arrow.
    • : Help <command>→ Display the help of related commands. You can also enter:helpInstead of commands. (Chen Hao Note: To exit the help, enter q)

    NormalMode. In a general editor, you need to useCtrlKey, for example:Ctrl-C. That is to say, the Ctrl key is like a function key. After you press the Ctrl key, C is no longer a C, and it is a command or a shortcut key,In Normal mode of VIM, all keys are function keys.. You need to know this.

      Ctrl-λI will write <C-λ>.
    • :You need to enter<enter>Press enter, for example,-if I write:qThat is, you need to enter:q<enter>.

      Various insert Modes
      A→ Insert after the cursor
    1. O→ Insert a new row after the current row
    2. O→ Insert a new row before the current row
    3. Cw→ Replace the character from the cursor position to the end of a word
    4. Simple move cursor
      0→ Zero number, to the row Header
    5. ^→ The first line of the line is not the position of the blank character (the so-called blank character is space, tab, line feed, carriage return, etc)
    6. $→ To the end of the row
    7. G _→ The last line is not the position of the blank character.
    8. /Pattern→ Searchpattern(Chen Hao Note: if multiple matches are found, press n to the next one)
    9. Copy/paste(Chen Hao Note: Both p and P can be used. p indicates that after the current position, P indicates that before the current position)
      P→ Paste
    10. Yy→ Copy the current rowddP
    11. Undo/Redo
      U→ Undo
    12. <C-r>→ Redo
    13. Open/Save/exit/change the file(Buffer)
      : E <path/to/file>→ Open a file
    14. : W→ Inventory
    15. : Saveas <path/to/file>→ Save<path/to/file>
    16. : X,ZZOr:wq→ Save and exit (:xSave only when needed. ZZ does not need to enter a colon and press Enter)
    17. : Q!→ Exit and do not save:qa!Forcibly exit all the files being edited, even if other files are changed.
    18. : BnAnd:bp→ You can open many files at the same time and use these two commands to switch to the next or previous file. (Chen Hao Note: I like to use: n to the next file)

      .→ (Decimal point) The last command can be repeated

    2dd→ Delete 2 rows
  • 3 p→ Paste the text three times
  • 100 idesu [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 ).
  • Never skip.

      G→ 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)
    1. Gg→ To the first line. (Chen Hao Note: equivalent to 1G, or: 1)
    2. G→ To the last line.
    3. W→ Start with the next word.
    4. E→ To the end of the next word.

    %: 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)
  • <Start position> <command> <end position>

    0y $Command means:

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

    YeFrom the current position to the last character of the word.

    Y2/fooTo copy the strings between two "foo.

      D(Delete)
    • V(Visualized selection)
    • GU(Change to uppercase)
    • Gu(Small write)
    (Chen Hao Note: Visual selection is a very interesting command. You can press v first and move the cursor to see the selected text. Then, you may d, y or uppercase)

    ^ $ 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.
    Dt"→ Delete all content until double quotation marks --"。

    <Action> a <object>Or<action>i<object>

    <Action> a <object>And<action>i<object>

      D(Delete ), y(Copy ), v(You can select the mode as needed ).
    • WOne word,WA word separated by spaces,sOne sentence,pA paragraph. It can also be a special character:"、 '、 )、 }、 ]。

    (Map (+) ("foo ")). The cursor key is in the first.

    Vi"→ Select foo.
  • Va"→ Select"foo".
  • Vi)→ Select"foo".
  • Va)→ Select("foo").
  • V2i)→ Selectmap (+) ("foo")
  • V2a)→ Select(map (+) ("foo"))
  • 0 <C-v> <C-d> I -- [ESC]

      ^→ To the line Header
    • <C-v>→ Start block Operation
    • <C-d>→ 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.

    Instead<C-v>,<C-v>Is to copy the clipboard.

    <C-n>And <C-p>

    <C-p> or <C-n> ......

    QaOperation Sequenceq,@a,@@

      QaRecord your operations in the register a。
    • @Macro that will replay the recording.
    • @@Is a shortcut key used to replay the macro of the latest recording.
    Example

      QaYp <C-a> q→
        QaStart recording
      • YpCopy rows.
      • <C-a>Add 1.
      • QStop recording.
    • @→ Write down 2 below 1
    • @@→ Write 3 in front of 2
    • 100 @@A new 100 row is created and the data is increased to 103.

    ,V,<C-v>

    <C-v>(In Windows, it should be <C-q>). We can usevAndV. Once selected, you can do the following:

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

    <C-v>

  • JOr<C-d>Or/patternOr%......)
  • $To the end of the line
  • A, Input string, pressESC。
  • Andvsplit.

    : Help split. You can refer to the previous article VIM split screen on this site.

    : Split→ Create a split screen ( :vsplitCreate a Vertical Split screen)
  • <C-w> <dir>: Dir is the direction, which can behjklOr one of them, which is used to switch the split screen.
  • <C-w> _(Or<C-w>|): Maximize the size (<C-w> | Vertical Split screen)
  • <C-w> +(Or<C-w>-): Increase the size.
    • : Help usr_02.txt.
    • !,Directory, register, plug-in, and many other functions.

  • 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.