Linux Learning---vi/vim (1. Basic knowledge)

Source: Internet
Author: User
Tags save file

VI and VIM have always been talked about, in the end what makes them so popular?

VI is divided into 3 modes: General mode, edit mode, command line mode.

(1) General mode:

After entering VI, the default is the general mode.

Useful: Easily move cursor, delete character/whole line, copy, paste.

Here are some common commands:

Method Explain Example
num + arrow keys Repeat direction key num times 20↑ is moving up 20 times.
num + Space Key Move num characters distance to the right 10<space> move 10 bits to the right.
0 or home key To the very front of the current line.
$ or END key Go to the last side of the line now.
G Move to the last row
num + G Move to Page Num. 10G means move to line tenth
Gg Move to the first row
num + ENTER Move num lines down 10<enter>, move down 10 lines.
/word Look down for Word this string /kaima means looking down Kaima this string
? Word Look up word for this string ? Kaima means looking up Kaima this string
: n1,n2s/word1/word2/g Find word1 between N1 and N2 rows and replace with Word2 10,20s/kaima/good/g find Kaima in the 10th to 20th row and replace it with good
: 1, $s/word1/word2/g Find word1 from the first line to the last row and replace with Word2 : 1, $s/kaima/good/g
num + x Continuous deletion of num characters 10x means delete 10 characters in a row
Dd Delete the current entire row
Yy Copy the current entire row
P, p P is pasted on the next line, p is pasted on the previous line
U Undo a previous action
[Ctrl] + R Repeat the last action

(ii) editing mode

Useful: Edit the content.

I,i I insert from the cursor, I insert from the first non-empty character of the current line prompt
A,a A prompt inserted from the next word of the cursor, a prompt inserted from the last word in the current line
O,o o Insert a new line below the current line, o insert a new row on the current line
R,r R replaces only the current character, R always replaces the character indicated by the cursor (ESC stop)

(c) command-line mode

Useful: Save, leave, modify settings.

: W Save File
: Q Leave VI
: Wq Leave after saving

Plus! To have a compulsive meaning, such as: w! Represents a forced save, even if the file is read-only.

These are just a few common commands, to meet the daily use, but this is not all, http://www.cnblogs.com/88999660/articles/1581524.html this article is a comprehensive list of the VI command, you can refer to.

Linux Learning---vi/vim (1. Basic knowledge)

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.