Linux under Vi/vim Use notes

Source: Internet
Author: User

Linux under Vi/vim use notes

Start and close vim

VI Open
Vi/vim

Open Vi/vim and load file <file>
VI <file>

ZQ Unconditional Exit
: q! Unconditional exit
ZZ Disk and exit
: Wq Disk and exit

Three modes of the VIM Editor: General mode, edit mode, and command line mode
You can delete, copy, and paste in normal mode, but you cannot edit the contents of a file.

Switch from general mode to edit mode to press I, I, O, O, A, a, R, R keys.

Note whether the current insert or Replace mode is being distinguished!

I: Insert to insert the input text from where the cursor is currently located.
A: increase, the current cursor is located in the next word start to enter text.
o: Insert a new line and enter text from the beginning of the beginning.

Press the ESC key to return to normal mode.

In the general mode, enter:,/,? Any one of the three can move the cursor to the bottom row.

In this mode, you can provide operations to find data, while reading, saving, mass substitution characters, leaving VII, displaying line numbers, etc. are done in this mode.

It is important to note that there is no switch between the edit mode and the command-line mode. after entering Vim is under "Command mode", to switch to insert mode to enter text. First Use VI users will want to first use the next key to move the cursor, the results of the computer has been prompted, so enter the VI, do not move, the conversion into insert after.


How to move the cursor:
[Ctrl]+[f]: The screen moves down one page, equivalent to the [PageDown] button.
[Ctrl]+[b]: The screen moves up one page, equivalent to the [PageUp] button.
0 or function key [Home]: Moves to the front character of this line.
$ or Function key [end]: moves to the last face character of this line.
G: Move to the last line of this file.
GG: Move to the first line of this file, equivalent to 1G.
N[enter]:n is a number, the cursor moves down n rows.


Find and replace:
Span style= "font-size:15px;" >/word: Look down for a string called Word.
?word: Looks up a string called word.
:n1,n2s/word1/word2/g: Looks for N1 between the N2 line and the Word1 row and replaces it with Word2.
:1, $s/word1/word2/g: look for word1 from the first line to the last line and replace it with Word2.
:1, $s/word1/word2/gc: looking for word1 from the first line to the last line, and replace it with WORD2. And the prompt character is displayed before the replacement to confirm that the user needs to be replaced.


Delete, copy and paste:
x,x: In a line of words, X is the backward deletion of one character (equivalent to the [Del] key), and X is a character (equivalent to [Backspace]) that is deleted forward.
DD: Deletes the entire line where the cursor is located.
NDD: Delete the down n rows where the cursor is located 。
yy: Copy the row where the cursor is located.
nyy: The next n line where the cursor is copied 。
p,p:p paste the copied content on the next line of the cursor, and P is pasted on the previous line of the cursor.
u: Restores the previous operation.
[ctrl]+r: Redo the previous operation.


General mode switch to edit mode:
I,i: Enter insert mode, I is inserted from the current cursor location. I begin the insertion at the first non-whitespace character at the current row.
A,a: Enter insert mode. A is the insertion starting at the next character where the cursor is currently located. A is inserted starting at the last character of the row.
O,o: Enter insert mode. O is inserted on the next line. O is inserted on the previous line.
R,r: Enter replacement mode. R replaces only the same character as the cursor. R will always replace the character of the cursor until the ESC key is pressed.


General mode switch to command line:
: W: Writes the edited data to the hard disk.
: Q: Leave VI behind add! To force leave.
: Wq: Leave after saving. : wq! to leave after forced save.

Linux under Vi/vim Use notes

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.