Use of the VI editor

Source: Internet
Author: User

How to move the cursor
H means left.
L represents the right
K means upward.
J means to think about it.
You can move more than one at a time by combining it with a combination, such as 30j to move down 30 rows
[ctrl]+[f] screen moves down one page, equivalent to page down
[Ctrl]+[b] screen moves up one page, equivalent to page up
[Ctrl]+[d] screen moves down half page
[Ctrl]+[u] screen move up midnight
[+] cursor moves to the next column of non-whitespace
[-] (not minus sign) cursor moves to the previous column of non-whitespace
N<space> N represents a number that represents the right-moving character if it is not enough to wrap the 20+space cursor to the right by moving 20
0 or the home key means back to the front of the line.
$ or Function key [end] moves to the character at the last Face
H The first character of the line that the cursor moves to the top of the screen
The first character of the line that the M cursor moves to the center
L cursor moves to the bottom of the screen the first character
G Move to the last line of this file
NG N Moves the number to the nth row of the file (not the current line)
GG moves to the first line of this file equivalent to 1G
N<enter> N is a number, the cursor moves down n rows

Search and replace
/word Word is a character that searches for a character below the cursor
Word word indicates that a character is searched for a character above the cursor
N (English character) is the/word of the previous action. Word is searched again
N (English characters) and N are the opposite
: n1,n2s/word1/word2/g N1 and N2 are numbers that are found between N1 and N2 rows Word1 use Word2 instead
: 1, $s/word1/word2/g represents the use of word1 instead of word2 between the first and last lines
: 1, $s/word1/word2/gc and above are the same meaning but will be user determined (confirm) whether it is necessary to replace
Delete, copy and paste on
X,x in a line of words, X is backwards
NX N continuously removes n characters backwards for numbers, for example, 10 characters in a row: [10x]
DD deletes the entire column where the cursor is located
NDD N is a number that removes the down N column where the cursor is located, for example, 20dd means to delete the 20 rows down
D1G Delete the first row of data where the cursor is located
DG deletes the last row of data where the cursor is located
d$ Delete the row of the cursor to the last row of data
The D0 number is 0 The character where the cursor is located to the front of the line
YY: The row where the copy cursor is located (put into the buffer, you need to use the P command to copy)
Nyy:n is the number of n rows following the digital copy cursor (placed in the buffer, which needs to be copied using the p instruction)
Y1G: Copy all data in the first row of the cursor
YG: Copy all data from the last line where the cursor is located
Y0: Copy the character of the cursor to all data at the beginning of this line
y$: Copies all the data at the end of the line at the same character as the cursor
P,p:p the copied data is pasted on the next line of the cursor and P is the previous line
J: Make the same column where the cursor is located and the next column
C: Repeat to delete multiple data if 10 lines down 10CJ
U: Restore previous action (equivalent to CTRL + Z of Windows)
[Ctrl]+r: Redo a previous action
“.” : Repeats the previous action
Enter edit mode
I,i: Enter insert mode I is inserted from the current cursor, and I begin inserting at the first non-whitespace space where I am currently in the row
A,a: Insert mode A indicates that inserting a from the next character of the cursor starts with the last character of the current line
O,o: Enter insert mode O next line in the current cursor
R,r:r will only replace the one character where the cursor is, and R will always be replaced (that is, it is covered backwards)
Instruction mode
: W Save Document
: w! If the file is read-only then mandatory save
: Q Leave VI
: q! If you have modified the document but do not want to save
: Wq Save and exit
: ZZ If not changed, do not store away, if changed, save and then exit
: w [filename] saves edited data to another document
: R [FileName] in the edited data, read the data of another file, add the content to the cursor row behind the
: n1,n2 w [filename] writes data between N1 and N2 rows to another document
Changes to the VIM environment
: Set NU Displays the line number, which, when set, displays the line number of the row in the prefix of each row
: Set Nonu with set Nu to cancel line number

Use of the VI editor

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.