Vim common commands [reprint]

Source: Internet
Author: User
Tags exit in

Reference: http://www.cnblogs.com/usergaojie/p/4583796.html

Vi:visual Interface Visual Interface
Vim:vi Improvedvi Enhanced Version

Full screen editor, modal editor

Vim mode:

    • Edit mode (Command mode)
    • Input mode
    • Last-line mode

Mode conversion:

Edit--Input:

    I: In front of the character of the current cursor, switch to input mode;
A: After the character of the current cursor, switch to input mode;
O: At the bottom of the current cursor line, create a new row and switch to input mode;
I: Converted to input mode at the beginning of the line at which the cursor is currently located
A: At the end of the line where the current cursor is located, convert to input mode
O: At the top of the current cursor line, create a new row and switch to input mode;

Input-to-edit:

    Esc

Edit-to-last line:

    :

Last line--edit:

    ESC, ESC

Note: There is no direct switch between the input mode and the last line mode

First, open the file
    Vim +#: Open the file and locate it on line #
Vim +: Open the file and navigate to the last line
Vim +/pattern: Open the file and navigate to the beginning of the line that was first matched to the PATTERN
Note: Default is in edit mode
Second, close the file

1, the last line mode closed file

    : Q  exit
: Wq Save and exit
: q! Do not save and exit
: W Save
: w! Forcibly saved
: Wq---: X

2. Exit in edit mode

ZZ: Save and exit

Third, move the cursor (edit mode)

1, character-by-word movement:

    H: Left
L: Right
J: Next
K: Up
#h: Moving a # character

2. Move in Word units

    W: Move to the beginning of the next word
E: Jumps to the ending of the current or next word
B: Jump to the beginning of the current or previous word
#w: Moving # words

3, in-line jump:

    0: The absolute beginning
^: first non-whitespace character at the beginning of a line
$: absolute end of line

4. Jump between rows

    #G: Jump To Line #
GG: First line
G: Last line

5, the last line mode

    .: Indicates when the forward
$: Last line
#: Line #
+#: Down # line
Four, turn the screen
    CTRL+F: Flip one screen down
Ctrl+b: Turn up one screen
Ctrl+d: Flip Down half screen
Ctrl+u: Flip up half screen
V. Delete a single character
    X: Delete a single character at the cursor location
#x: Remove the total # characters from the cursor and backwards
Vi. Delete command: D

The D command is used in combination with the jump command

    #dw, #de, #db

DD: Deletes the current cursor in the row
#dd: Delete the line containing the line of the current cursor;

Seven, Paste command p
    P: If you delete or copy to an entire row, paste to the bottom of the line where the cursor is located, and if the copied or deleted content is a non-full row, paste it after the character that contains the cursor
P: If you delete or copy to an entire row, paste to the top of the line where the cursor is located, and paste to the front of the character where the cursor is located if the copied or deleted content is not a whole line
Eight, copy command y
    Usage with d command
Nine, modify: First delete the content, and then converted into the input mode
    C: Usage with d command
Ten, replace:
    R: Single-character replacement
#r: # Characters after the cursor replace all
R: Replacement mode
Xi. undo Edit Operation U
    U: Undo the previous edit operation
#u: Undo Recent # edits directly
The continuous u command undoes the previous n edit operations
Undo the most recent undo action: Ctrl+r
12. Repeat the previous edit operation
    .: Edit mode repeats previous edit operation
13. Visualization Mode
    V: Select by character
V: Select by rectangle
14. Find
    /pattern
? PATTERN
N Next
N Previous
XV, find and replace

Use the S command in the last-line mode

    Headline,footlines#pattern#string#g
1,$: Express Full text
%: Full text
16. Use Vim to edit multiple files
    Vim FILE1 FILE2 FILE3
: Next switches to the next file
:p Rev Switch to the previous file
: Last switch to final file
: first to switch to file one
: Q Exits the current file
: QA All exits
17, split screen display a file
    Ctrl+w, S: Horizontal splitter window
Ctrl+w, V: Vertical splitter window

Toggle the cursor between windows:

    
: QA Closes all windows
18. Edit multiple files in a window
    Vim-o: Horizontal Split display
Vim-o: Vertical Split display
19. Save some of the contents of the current file as a different file

Use the W command in the last row mode

    : Addr1,addr2w/path/to/somewhere
20. Populate the contents of another file in the current file
    : R/path/to/somefile
After attaching to the current file cursor
21. Interacting with the shell
    :! COMMAND
22. Advanced Topics

1. Display or suppress line numbers

    : Set Nu
: Set Nonu
MU = number

2. Display ignores or distinguishes character case

    : Set IC
: Set Noic
IC = ignorecase

3. Set Auto Indent

    : Set AI
: Set Noai
AI = autoindent

4. Check the found text highlighting or canceling

    : Set Hlsearch
: Set Nohlsearch

5. Syntax highlighting

    : Syntax on
: Syntax off
Note: The feature is currently valid, if you want to permanently effect the configuration file 23, configuration file
    /ETC/VIMRC    for all users
~/.VIMRC for the current user



Vim common commands [reprint]

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.