Linux Learning one of the basic uses of the--VI editor

Source: Internet
Author: User

The VI Editor is the standard editor for Linux systems. And not inferior to any of the other latest editors. But how much is it going to be used? Here's a brief introduction to the VI Editor and some commands. Let's get you on the Linux system.

Basically, vi can be divided into three states, namely command mode, insert mode, and bottom line mode.

1) command-line mode commands to control the movement of the screen cursor, the deletion of characters, words or lines, moving and copying a section and entering insert mode, or to last line mode.     2) Insert mode is only available for text input, and press "esc" to return to command line mode. 3) bottom row mode (last lines) Save or exit VI, or you can set the editing environment, such as searching for strings, listing line numbers ...     such as In general, however, we simplify the VI into two modes when we use it, that is, the bottom row mode (last line mode) is also counted as the command-line pattern.

First, enter the Linux command-line interface. Create a text file (touch filename) for testing in the directory. I've created a new test12 text file here. Of course, the name can be obtained casually. Use the "vi test12" command to enter the VI command line mode (vi filename).  If you want to edit a text file. You have to switch to insert mode, which means "I" on the keyboard. This allows you to edit the text and delete the contents of the text. Press the left and RIGHT arrow keys on the keyboard. Move back and forth. Just as you would edit text in a Windows system. Enter what you want to enter. If you want to exit text-editing mode. And save the text you just edited. First click on "ESC" on the keyboard and enter ": wq!" This saves the text. Then the VI Editor is released. If you do not want to save, click "ESC" on the keyboard and enter ": q!". If you are not sure if you are successful. You can view it through the cat filename command.

The cursor moves in addition to the upper and lower keys on the keyboard. It can also be in lowercase mode, press "H,j,k,l" on the keyboard,

"Ctrl+b": the screen moves backward one page

"ctrl+f": Screen moves forward one page

"Ctrl+u": Screen moves backward half page

"Ctrl+d": Screen moves forward half a page

Enter any integer and enter "Shift+g" to the beginning of this page.

Press the uppercase "G" on the keyboard to move to the end of the article.

Press the "$" symbol to move the cursor to the end of the line

"^" Moves the cursor to the wardrobe

"W": Moves the cursor to the next line header

"B": Contrary to "w". Move to the previous line of the outfit

"E": Moves the cursor to the end of the next line.

If you want the text to display line numbers. In command-line mode, enter the ": Set nu" command at the end of the text. It's okay.

    1. Copy "yw": Copies the characters from the cursor to the end of the word into the buffer.   "yy": Copy cursor line to buffer.   "#yy": for example, "6yy" represents a copy of 6 lines of text from the line where the cursor is located. "p": Paste the characters in the buffer to the cursor location. Note: All copy commands related to "Y" must be mated with "P" to complete the copy and paste function.

    2. 6

      Find

      Use "/" plus the content you want to find. For example, "/hello" or "? Hello" is also possible.

      1. Replace "r": Replaces the character at which the cursor is located.  , click on "R" and type. "r": Replaces the character where the cursor is located until the "esc" key is pressed.

      2. 8

        Redo Last Action "u": If you mistakenly execute a command, you can press "u" immediately to go back to the previous action. Multiple restores can be performed by multiple "U". This is equivalent to the "CTRL +z" operation.

Linux Learning one of the basic uses of the--VI editor

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.