Common VI commands and buttons

Source: Internet
Author: User
1. Store and exit files
: WQ or: X save the file and exit vi
ZZ save and exit (: X indicates to save only when needed, ZZ does not need to enter a colon and press Enter) ZZ = WQ
ZQ exit unconditionally
: E filename open file filename for editing [equivalent to exiting the current file and opening another file]
: E! Discard modifying file content and reload the file for editing
: E Re-load [similar to refresh]
CTRL + z/FG temporarily mounted to the background/jump back Edit page
: F or Ctrl-G display the file name and some other information
:! Command temporarily exits VI and executes shell commands. After the command is executed, return to VI
: R! Command: place the output result of command to the current line. [strong]
The Newly Edited vim-x exam.txt file is encrypted, and a prompt is displayed for entering the password.
: X file encryption. A prompt is displayed for entering the password.
: Map: lists the currently defined mappings (how to define mappings ?)
: Jumps lists the locations you have jumped to. The last one is marked with a "> ".
: Marks: Lists custom tags, including the vim internal custom tags.
: %! NL numbers all rows that contain empty rows (the row number is inserted before all rows ^ I)
: Version: displays Vim version information, including features, compilation methods, and configuration file directories.
: Options to open a new window, the comment at the beginning of the window is a list of options (do what ?)
: R filename Insert the content of a file (read) at the cursor location to add a number: NR filename
: F filename: Changing the file name in the editing process is equivalent to copying a file. After executing this command, the new editing will not apply to the original file.
GF Vim special method to open a file, open the file named after word where the cursor is located, of course, this file must be in the current directory, otherwise a new file will be created

2. Move
(1) Words
W cursor jump to the first letter of the next word [common]
W moves to the beginning of the next word, ignoring punctuation
B. move the cursor back to the first letter of the previous word.
B moves to the beginning of the previous word, ignoring the punctuation mark back
E. move the cursor to the last letter of the next word.
E. Move to the end of the next word and ignore the punctuation mark "end ".
The end of the word before GE
Ge
(2) rows
N + move the cursor down n rows [SHIFT + by the last key]
N-move n rows above the cursor
[[File start position -- start line
] File end position-end line
H move the cursor to the head of the screen
M moves to the middle line of the screen and starts with middle
L move to the last line of the screen.
(Move the cursor to the beginning of the sentence.
) Move the cursor to the end of the sentence
(3) Paragraph
* And # match the current word of the cursor, move the cursor down (or up) to a match word (* is next, # Is previous)
ZF fold (direction keys required)
Expand Zo (space can also be expanded)
(4) Screen
CTRL + u flip to the first half of the file up
CTRL + D flip the half screen to the end of the file down
CTRL + F flip a screen at the end of the file forward (fact goes to two rows on the whole screen)
CTRL + B flip a screen back to the first part of the file (fact goes to two rows on the whole screen)
CTRL-] Jump to the topic corresponding to the word with the current cursor
CTRL-O back to previous location
The ZZ command sets the current line to the center of the screen (the Z word takes its pictogram meaning to simulate the folding and deformation position reset of a piece of paper)
The ZT Command places the current line at the top of the screen)
The ZB Command places the current line at the bottom of the screen (bottom)
50% cursor positioned in the middle of the file
'Jump to the position where the cursor is located recently (only the last two positions can be remembered ).

3. insert
I insert characters at the beginning of the current line
A starts to add words at the end of the row where the cursor is located.
S deletes the character where the cursor is located by default, and the input content is inserted = xi
S deletes the content of the current row by default. The input content is used as the new content of the current ROW = dd + O

4. Delete
(1) characters
NX deletes n characters (including the cursor position) starting from the cursor position X = DL (delete the characters under the current cursor)
NX deletes n characters (including the cursor position) before the start of the cursor position X = DH (delete the character on the left of the current cursor)
D0 Delete to the beginning of a row
D $ Delete to the end of the row
DFA indicates removing the content from the current cursor to the first a character after the cursor
D Represents d $ (content deleted to the end of the row)
C stands for C $ (content modified to the end of the line)
(2) Words
Ndw deletes n-1 characters starting at and following the cursor.
NDB deletes n-1 characters starting at and before the cursor.
DIW deletes the word with the current cursor (excluding blank characters), meaning the word between the delete inner word
DAW deletes the word (including blank characters) where the current cursor is located, meaning delete a word
(3) rows
DG deletes content from the current row to the end of the file
DGG deletes contents from the current row to the file header
CW deletes the current word and enters the input mode. [easy to use, change a word quickly] is equivalent to DW + I
NCW deletes the current word and its N-1 characters, and enters the input mode \ modifies the specified number of words
CC deletes the current row and enters the input mode
NCC deletes the current row and the n-1 row after it, and enters the input mode
Words under the guw cursor become lowercase
The words under the guw cursor are capitalized.
XP switch between two characters around the cursor
Ga displays the internal code of the character under the cursor under the currently used Encoding

5. copy and paste
(1) Copy
Y0 indicates copying the content from the current cursor to the beginning of the row where the cursor is located
Y $ copy from current position to end of row
Yfa indicates copying the content from the current cursor to the first a character after the cursor
YG copies the data from the row to the last row.
P copies the temporary data row on the top of the cursor.
: N1, N2 Co N3 copy content from line N1 to line N2 to line N3 + 1 [next line of line N3]
: N1, N2 M N3 move the content from line N1 to line N2 to line N3
~ Change the case sensitivity of characters under the current cursor
 
6. Search
/Pattern Search for pattern from the beginning of the cursor to the end of the file
? Pattern searches for pattern from the beginning of the cursor
# What is the equivalent of a complete match of words under the cursor? Word
* Completely match the word under the cursor down to the equivalent of/Word
 
7. Replace
: % S! \ S *//.*!! Remove all "//" Comments
: % S! \ S */\ * \ _. \ {-} \ */\ s *!! G. Remove all "/**/" comments.
: % S = * $ = Delete unnecessary spaces at the end of all rows (not clear)
: G/^ \ s * $/D: delete all blank lines that do not contain characters (spaces are not included)

Reference: http://blog.csdn.net/wklken/article/details/7533272

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.