Learn Linux_08_vi using from scratch

Source: Internet
Author: User

Welcome to read the reference, if there are errors or questions, please leave a message to correct, thank you

First, what is VI1, what VI:VI is the most commonly used text editor under Linux/unix.
2, Vim:vim is the upgrade version of VI, it is not only compatible with all the VI commands, but also added some new features.


Three modes of operation of VI


Three, edit mode 1, cursor positioning 2, search string (:., $s/str1/str2/g   look for the str1 string between the current line and the last row, and replace the string with STR2! )3. Replacement and deletion
4. Cut and paste
5. Revocation and repetition
The details are shown in the following table:
General mode: Move cursor
h or LEFT ARROW key The cursor moves one character to the left
J or DOWN ARROW key Move the cursor down one character
K or UP ARROW key Move the cursor up one character
L or RIGHT ARROW key The cursor moves one character to the right
[Ctrl] + [f] screen "forward" move one page ( common )
[Ctrl] + [b] screen "Backward" Move one page ( common )
[Ctrl] + [d] Screen "forward" to move half a page
[Ctrl] + [u] The screen "backwards" moves half a page
+ Cursor moves to the next column of non-whitespace
- Cursor moves to the previous column of non-whitespace
N<space> When you press the number and then press the SPACEBAR, the cursor moves the n characters of the line to the right. For example 20<space>, the cursor moves 20 character distances to the back.
0 This is the number "0": Move to the front of the line prompt ( common )
$ move to the last face of this line prompt ( common )
H The cursor moves to the top row of the screen.
M The cursor moves to the center of the screen.
L The cursor moves to the bottom line of the screen
G move to the last line of this file ( common )
NG Move to the nth row of this file. For example 20G will move to 20 lines of this file (mates: Set Nu)
N<enter> move the cursor down n rows ( common )
General mode: Search and replace
/word look for a string after the cursor with a string name of Word. ( common )
? word Look for a string with the string name Word before the cursor.
: n1,n2s/word1/word2/g look for the string word1 between N1 and N2, and replace the string with Word2! ( common )
: 1, $s/word1/word2/g look for the word1 string from the first line to the last line and replace the string with Word2! ( common )
: 1, $s/word1/word2/gc look for the word1 string from the first line to the last line and replace the string with Word2! and display the prompt character before the substitution to the user to confirm (conform) whether need to replace! ( common )
General mode: Delete, copy and paste on
X, X x to remove one character backwards, X to delete one character forward ( common )
Nx Remove n characters backwards
Dd Delete the entire column where the cursor is located ( common )
Ndd Delete the down n column where the cursor is located, for example, 20DD to delete 20 columns ( common )
d1g Delete all data from the first row of the cursor
Dg Delete all data from the last row of the cursor
Yy The row where the cursor is copied ( common )
Nyy Copy the down n column where the cursor is located, for example, 20yy to copy 20 columns ( common )
y1g Copy all data from the column to the first column of the cursor
YG Copy all data from the column to the last column of the cursor
P, p p for the copied data is pasted on the next line of the cursor, p is affixed to the cursor on a row! ( common )
J Combine data from the cursor column and the next column into the same column
C Repeatedly deleting multiple data, such as deleting 10 rows down, [10CJ]
U restores the previous action. ( common )


Iv. Insert mode (edit mode)
Enter edit mode
I, I Insert: Inserts the input text at the current cursor position, and the existing text will be backward; ( common )
A, a Added: The current cursor is the next word in the beginning of input, the existing text will be back: ( common )
O, O Insert a new line: Enter text from the beginning of the next line where the cursor is located; ( common )
R, R Replace: R will replace the character where the cursor is located , and R will always replace the text of the cursor until ESC is pressed; ( common )
Esc exit edit mode, return to normal mode ( common )


Five, Command mode (last line mode)
Instruction-column Command mode
: W write the edited data to the hard drive archive ( common )
: w! If the file property is read-only, the archive is forced to write
: Q Leave VI ( common )
: q! If you have modified the file, do not want to store, use! Do not store files for forced departures.
: Wq save after leaving, if: wq! is forced to save after leaving ( common )
: e! Restore the file to its original state!
Zz If the file does not change, then do not store away, if the file has been changed, then the store left!
: w [filename] Save edited data to another file (similar to save new file)
: R [FileName] In the edited data, read the data from another file. The file "filename" will be added to the cursor row after the
: Set Nu Displays the line number, which, when set, displays the line number of the row in the prefix of each row
: Set Nonu In contrast to set NU, the line number is canceled!
N1,N2 w [filename] Store the contents of N1 to N2 into the filename file.
:! Command Temporarily leave VI to command column mode to perform command display results! For example [:! ls/home]

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Learn Linux_08_vi using from scratch

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.