Common commands of vi in Linux

Source: Internet
Author: User
I have read the vim program editor chapter in "laruence's Linux private House dish" and made the following records on common vi operation commands for reference. I. The third mode of Vi is basically divided into three modes: "General mode" and "Edit mode" without "command column command mode 』. These three...

I have read the "vim program editor" chapter in "laruence's Linux private House dish" and made the following records on common vi operation commands for reference.

I. III mode of Vi

Basically, vi is divided into three modes: "General mode" and "Edit mode" instead of "command column command mode 』. What are the three modes? The functions are as follows:

1. general mode: open an archive using vi? This is the default mode ). In this mode, you can use the "up/down" button to move the cursor. you can use the "delete character" to stop "deleting the entire line" to process the file content, you can also use "copy and paste" to process you? File data.

2. Editing mode: In normal mode? Are rows deleted, copied, and pasted? But cannot edit the file content! It takes you to press "I, I, o, O, a, A, r, R" and other letters to enter the editing mode. Note! In Linux, when you press these buttons? "INSERT or REPLACE" appears in the lower left corner? Edit rows. To return to normal mode, you must press the "Esc" button to exit the editing mode.

3. Command column mode: in general mode, enter 『:/? ? Any button can move the cursor to the bottom line. In this mode, you can search for information, while reading, saving, replacing a large number of characters, leaving vi, displaying a row number, and so on are achieved in this mode!

 

Simply put, we can think of the three modes as the icons below:

 

II. common vi Operation Commands

1. how to move the cursor

H or move the cursor to the left arrow (Arrow) ------- move the cursor to the left

J or the down arrow (Arrow) -------- move the cursor down a character

K or the up arrow (Arrow) ------- move the cursor up a character

L or right arrow (→) -------- move the cursor one character to the right

 

Ctrl + f --------- flip a screen to the end of the file, which is equivalent to a Page Down button

Ctrl + B -------- flip the screen to the beginning of the file, equivalent to the Page Up Button

G -------------- move to the last row of the file

Gg ------------- move to the first line of this file

NG ------------ n indicates the nth row to be moved to this file.

N ---- Move the cursor down n rows

 

2. search and replace

/Word -------- search for a string named word under the cursor

? Word ------- search for a string named word over the cursor

N ------------ This n is an English button. Indicates "repeat the previous search action 』. For example, if we just run/vbird to search for the vbird string, press n to continue searching for the next string named vbird. If it is execution? Press n to search for a string named vbird!

: N1, n2s/word1/word2/g ------ n1 and n2 are numbers. Search for the word1 string between line n1 and line n2 and replace it with word2! For example, if you search for vbird between 100 and 200 rows and replace it with VBIRD: ": 100,200 s/vbird/VBIRD/g 』

: 1, $ s/word1/word2/g ------ search for the word1 string from the first row to the last row and replace it with word2!

: 1, $ s/word1/word2/gc ----- searches for the word1 string from the first row to the last row, and replaces the string with word2! The prompt characters are displayed before replacement to confirm (confirm) whether to replace!

 

3. delete, copy, and paste www.2cto.com

X, X ------ in a line of text, x is to delete a character backward (equivalent to a [del] Key), and X is to delete a character forward (equivalent to a blank [backspace] or a backspace key)

Dd ------ delete the entire column of the cursor

Ndd ----- n is a number. Delete the n-down column where the cursor is located. for example, if 20dd is used, 20 columns are deleted.

Yy ----- copy the row of the cursor

Nyy ----- n is a number. Copy the n-down column where the cursor is located. for example, if 20yy is used, 20 columns are copied.

P, P ----- p: is it copied? Data is pasted on the next row of the cursor, and P is pasted on the previous row of the cursor! For example, I have already copied 10 rows of data with the cursor in 20th rows. After you press p, the 10 rows of data will be pasted after the original 20 rows, that is, from 21 rows. But what if I press P? Then the original 20th rows will be pushed to 30 rows.

U ------ restore the previous action.

[Ctrl] + r ----- redo the previous action.

 

 

 

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.