Common VI commands in Ubuntu

Source: Internet
Author: User

 

You often need to modify some files in Ubuntu. Here we will summarize some common operations in VI.

1. Enter the VI command

VI filename: open or create a file and place the cursor at the beginning of the first line

After entering the file, it is in command mode)

2. Switch to the command line mode.

Press ESC

3. insert mode)

In command mode, press the letter

I insert before the cursor;
A is inserted after the cursor;

I insert at the beginning of the row where the cursor is located;
A is inserted at the end of the row where the cursor is located;

O insert a row above the row where the cursor is located;
O insert a row under the row where the cursor is located;

S. delete a character after the cursor and enter the insert mode;
S. Delete the row where the cursor is located and enter the insert mode;

4. Deletion Mode

In command mode, press the letter

X deletes a character from the cursor;

Dd deletes a row;
# X delete several characters, # indicates a number, for example, 3x;
DW deletes a word;
# DW deletes several words. # It is represented by numbers. For example, 3dw deletes three words;
# Dd deletes multiple rows and # represents numbers. For example, 3DD deletes the cursor row and the cursor's next two rows;
D $ Delete the content from the cursor to the end of the line;
J. Clear the space between the row where the cursor is located and the previous line, and link the cursor row with the previous line;

 

5. Replacement

In command mode, press the letter

R replaces the character at the cursor

R replaces the character wherever the cursor goes until you press the ESC key.

 

6. Exit

: WQ! Or: X Save the modification and exit.

: Q! Exit Without saving changes

 

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.