Basic operation of Linux VI

Source: Internet
Author: User

Enter command

VI < file name >

such as VI test

If the test file exists, the edit is opened directly. If it does not exist, a new test file is created, and the newly created file will not be saved to the hard disk if it is not saved.

Operating mode

Edit mode and command mode.

The default is command mode when entering. In addition to adding and reducing text edits, copy, delete, copy, and paste all operate in command mode.

Enter edit mode after inserting commands such as a, I, S, O, and so on.

Edit mode switches to command mode, pressing the ESC key of the keyboard.

Enter edit mode

A: Inserts a new character from the back of the cursor, and when inserted, the character that follows the insertion moves backwards with the new character.

A: Add a new character from the last point of the line where the cursor is located.

I: Inserts a new character from the front of the cursor, and when inserted, the character that follows the insertion moves backwards with the new character.

I: A new character is added before the first non-null character in the line where the cursor is located.

O: Add a blank line below the line where the cursor is located and enter the insert state.

O: Add a blank line above the line where the cursor is located and enter the insert state.

S: Deletes the character at which the cursor is located and enters the insertion state.

S: Deletes the line where the cursor is located and enters the insert state.

Here is the command mode operation

Save and exit

: Q: Exit VI.

: q!: Discard current edits made to edit, and force exit VI.

: Wq: Save to exit.

: w [< file name;]: Save As. Save the content you are editing with the name of the < file > name (equivalent to saving as ...) ), if no < file name is specified, then the original file name (equivalent to save ...) is used. )。

Select Block

E: From the current position of the cursor to the last character of the current word.

B: From the current position of the cursor to the first character of the previous word.

$: From the current position of the cursor to the last character of the line.

): From the current position of the cursor to the first character of the next sentence.

3): The first character from the current position of the cursor to the third sentence in the back.

{: From the current position of the cursor to the first character of the current paragraph.

}: From the current position of the cursor to the first character of the next paragraph.

Cut Copy Paste Delete and undo

d< Range > Delete a piece of content

y< Range > Replication, (y = Yank)

P Paste

X: Deletes the character at which the cursor is located.

DD: Deletes the line where the cursor is located.

D: Removes all characters from the beginning of the cursor until the end of the line.

U: Restores the text that was just deleted.

U: Restores all changes in this edit to the line where the cursor is located.

Find

f<;: Moves the cursor to the right from the point where the cursor is located to the first occurrence < character >.

f<: Start with the cursor and move the cursor to the left to the first place where < character > appears.

;: Used with F and F commands to continue searching in the same direction.

, which is used with the F and F commands to continue to retrieve in the opposite direction.

/< string: Starting at the cursor, search for the first < string >, then place the cursor there.

?< string;: Start with the cursor, search forward to the first < string >, and then place the cursor where it is located.

N: Use with/with the command to continue searching in the same direction.

N: Use with/with the command to continue searching in the opposite direction.

Move cursor

←↑→↓: Move the cursor on the left, top, right, and bottom.

H, K, L, J: Move the cursor on the left, top, right, and bottom.

0 (0): Moves the cursor to the beginning of the line.

$: Moves the cursor to the end of the line.

H: Moves the cursor to the beginning of the first line of the current window (not the full text).

M: Moves the cursor to the beginning of the center line of the current window.

L: Moves the cursor to the beginning of the last line in the current window.

W: Moves the cursor to the first character of the next word (word).

B: Move the cursor to the first character of the previous word.

E: Moves the cursor to the last character of the current word.

< number >g: Move the cursor to the < number > line header.

-: Moves the cursor to the first non-empty character on the previous line.

+: Moves the cursor to the first non-empty character on the next line.

< number >-: Moves the cursor to the first non-empty character of the top < number > line.

< number >+: Moves the cursor to the next < number > line at the first non-empty character.

(: Moves the cursor to the front of the current sentence, where the sentence is!.? Three kinds of symbols are defined.

): Move the cursor to the front of the next sentence.

< number > (: Moves the cursor to the front < number > first of the sentences.

< number >): Moves the cursor to the back < number > The front of a sentence.

{: Move the cursor to the front of the current paragraph of the cursor where the paragraph is defined by a blank line between the paragraphs.

}: Move the cursor to the front of the next paragraph.

< number >{: Moves the cursor to the front < number > first of paragraphs.

<: Move the cursor to the top of the < number > paragraphs.

Basic operation of Linux VI

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.