Vim Operation Guide

Source: Internet
Author: User
Tags save file

VIM has 6 basic modes and 5 derivation modes.

  • Basic mode

    • Normal mode

    • Insert mode

    • Visual mode

    • Selection mode

    • Command-line mode

    • Ex Mode

  • Derived mode

      • Operator wait mode

      • Insert Normal Mode

      • Inserting visual mode

      • Insert Selection Mode

      • Replacement mode

1. Move the cursor (normal mode)

H: Left

J: Next

K: Up

L: Right

2. Insertion mode and method of exiting Vim

LS: Displays the file under the current path

vi+ FileName: Open the file, default into normal mode, you can use the arrow keys described in 1, press I, that is, enter the insertion mode (the bottom left corner can see the insert word).

Exit Insert mode: Press ESC to return to normal mode.

Various ways to enter insert mode:

Tap button meaning
I Enter insert mode in front of cursor
I Enter insert mode at the beginning of the line where the cursor is located
A Enter insert mode after the cursor
A Enter insert mode at the end of the line where the cursor is located
O Inserts a blank line below the line of the cursor and enters insert mode
O Inserts a blank line above the line of the cursor and enters insert mode
S Removes the specified character from the cursor and enters insert mode
S Clears the cursor line and enters insert mode

Ways to exit Vim (multiple command line mode):

: q! : Force quit, do not modify

: Wq : Save Exit

3. Delete commands, digital secret, undo and Redo Commands
    • Delete command

      1. In normal mode, deleting a single character can be used with the X command

      2. Delete More characters can use the D command (delete), using the method: D+motion

      motion--an instruction that represents the scope of operation

Key meaning
0 Position the cursor at the beginning of the line
^ Ditto
$ Move the cursor to the position of the row bit
B Position the cursor at the beginning of the word where the cursor is located
E Position the cursor at the end of the word where the cursor is located
W Position the cursor at the beginning of the next word
Gg Position the cursor at the beginning of the file
G Position the cursor at the end of the file

Key meaning
D0 Removes all characters from the current position (not included) to the beginning of the line
d^ Ditto
d$ Delete all characters from the current position of the cursor (not included) to the end of the line
Db Delete all characters from the current position of the cursor (not included) to the beginning of the word
De Remove all characters from the cursor's current position (contained) to the end of the word
Dw Removes all characters from the current position (contained) to the beginning of the next word
Dh Remove one character from the front of the cursor
Dl Delete the character specified by the cursor
Dj Remove all characters from the row and the next line of the cursor
Dk Remove all characters from the row and previous line of the cursor
Dd Remove all characters from the line where the cursor is located
DGG Delete all characters from the line to the beginning of the file
Dg Delete all characters from the line to the end of the file
    • The Secret of Numbers

      1. Digital +motion: Repeating multiple motion

      2.d+ Digital +motion: Deleting multiple motion Ranges

    • Revoke

      1.u means undo last modification

      2.U means undo modification of the entire row

      3.commend+r shortcut keys to restore undone content

      4. All deletions are not really deleted, but are stored in a buffer of vim, equivalent to the clipping function

4. Paste command, replace command, replace mode and modify command
  • paste command

    • use the delete command under VIM and do not delete your things directly, Instead, it is placed in a vim register.

    • use the P command to paste the last deleted content after the cursor (large The write p can be pasted before the cursor)

    • Note:

      • if you pasted an entire line, the P command will be pasted on the next line of the cursor

      • If you paste a local string, the P command starts pasting after the cursor

  • Copy command

    • Vim with Y (Yank) command for copy: y[number] Motion

      • YY: Copy when moving forward

  • Replace command

    • The r command replaces the character of the cursor by first moving the cursor to the character that needs to be replaced, pressing the R key, and then entering the new character

    • Enter a number before you type the R command, indicating that multiple characters are uniformly replaced with new characters starting at the cursor

    • The r command goes directly into the replacement mode

  • Modify command

    • modifications and substitutions are not the same , the modification goes into insert mode, and the substitution does not enter insert mode

    • Vim with C command implementation modification: c[digital]motion

5. File information, jumps, positioning brackets, and indents
  • Control+g: Displaying file information

  • Jump

    • Line number +g

    • : line number

  • Locating brackets

    • Press the% key to quickly find the other half bracket

  • Indent (indent in C language style)

    • >> Right indent,<< left indent, number + indent to enable multiline indentation

    • Press V to enter visual mode, press HJKL to select the row, and then press >

6. Search command and Replace command
    • Search command

/target
  ? target
search direction start backward from the cursor start with the cursor forward
n Search Backward Next forward search next
N search forward next search Backward next
    • Cancel Highlight:: Nohl

  • Ten special characters

    • . * [ ] ^ % / ? ~ $ cannot search directly for these 10 characters, to add \ Escape

  • Replace command

    • : s/old/new

      • Replaces the first old of the row where the cursor is located with the new

    • : s/old/new/g

      • Replaces all the old of the row where the cursor is located with the new

    • :%s/old/new/g

      • Represents replacing all old in the entire file with the new

    • :%S/OLD/NEW/GC

      • Same as above, but will consult before each replacement

    • : 5,13s/old/new/g

      • Replaces all old as new in line 5th through 13th

7. Execute shell commands, save files as, merge files, and open multiple files
  • Execute shell command

    • :!

  • Save File as

    • : W file name

  • Save local content as

    • 1. Enter the visual mode

    • 2.:w file name

  • Merging files

    • : R file Name

  • Open multiple Files

      • -O Vertical Side-by

      • -O Horizontal Side-by

      • Use CONTROL+W+W to switch the cursor to the next file

      • For vertically-side files: Use the control+w+ up/down direction

      • For horizontally-side files: Use control+w+ around direction

      • : QA Exits All Files

      • : WQA Save All changes

      • : qa! Ignore All modifications

Vim Operation Guide

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.