Linux Learning Notes (4)-Use of the text editor VI

Source: Internet
Author: User
Tags save file

  • Three editing modes for VI
  • Command mode

    You can control the movement of the cursor in this mode, you can delete characters, delete rows, and copy and move a paragraph

  • Input modes (Insert mode)

    You can enter characters only in this mode

  • Last-line mode

    you can save or exit a file in this mode Vi, you can also set the editor environment, you can also find strings, list line numbers

    Note: But generally think of VI as two two modes, the last line mode is also counted in the command line mode

  • Early Vi Experience

    Type VI file.txt at the terminal

    #VI file.txt

    If the unfamiliar person is sure to start directly, tapping the keyboard to enter, found no effect, began to anxious. In fact, when you enter the above command, it is in command mode at this time. To switch to the input mode before you can enter, just press the letter "I", so you can enter, to switch to command mode, just press "ESC" key.

    Save File

    in command-line mode, click the ":" key to enter the last-line mode, such as:

    : w filename ( save file with filename)

    : Wq (save and launch VI)

    : q! (do not save the mandatory exit VI)

  • Command mode function keys
  • Switch to input mode

    Enter the file from the current position after entering input mode by pressing "I"

    When you enter input mode by pressing "a", enter the text from the next position where the cursor is currently located.

    When you enter input mode by pressing "o", you insert a new line and enter the text from the beginning of the beginning.

  • Switch from input mode to command mode

    Press "ESC" key

  • Move Cursor

    VI can be directly with the cursor on the keyboard to move up and down, but the normal vi is a lowercase letter h,j,k,l control the left, bottom, upper, and right of the cursor one grid

    Press "Ctrl" + "b": Screen moves to "back" page

    Press "Ctrl" + "f": screen to move one page toward "front"

    Press "Ctrl" + "u": Screen moves half page toward "rear"

    Press "Ctrl" + "d": Screen to move half page toward "front"

    Press number 0: Move to the beginning of the article

    Press G: Move to the end of the article

    Press $: move to the end of the line where the cursor is located

    Press ^: Move to the beginning of the line where the cursor is located

    Press #l: The cursor moves to the first # position of the line , such as 5l

  • Delete Text

    Press x: Every time you click, delete the "after" character at the location of your cursor

    Press #x: such as 6x to delete the 6 characters after the cursor position

    Press x: uppercase X to delete the previous character in the position of the cursor each time it is pressed

    Press #X: Delete the # characters before the cursor

    Press DD: Delete the line where the cursor is located

    Press #dd: Deletes the # line starting at the line where the cursor is located

  • Copy

    Press yw: Copies the character at the end of the cursor to the buffer

    Press #yw: Copy # words to buffer

    by yy: Copy cursor line to buffer

    Press #yy: From the line where the cursor is located, count down # lines to the buffer

    Press P: To paste thecharacter of the buffer to the cursor location, allcommands relatedto "Y" must be mated with "P" to complete the copy and paste function

  • Replace

    Press R: Replace the character at which the cursor is located

    Press R: Replaces the character at which the cursor is located, knowing that the ESC key is pressed

  • Undo Last Action

    Press u: If you mistakenly execute a command, you can press "U" immediately to go back to the previous action. multiple "u" can be executed multiple times.

  • Change

    Press "CW": Change the word at the end of the cursor

    Press "c#w": For example, "c3w" means change of 3 words

  • Jumps to the specified row

    Press ctrl+g to list the line number of the line where the cursor is located.

    Press #G: For example, "15G", which means moving the cursor to the beginning of the first line of the article .

Introduction to the last line mode

Before using "last line mode", remember to press "esc" to make sure you are under "command mode" and then press ":" Colon to import into "last line mode".

  • Column Travel number

    "set nu": After you enter "set nu", the line numbers are listed before each line in the file.

  • Jump to a line in a file

    The "#":"#" number represents a number, enter a number after the colon, and then press ENTER to jump to the line, such as entering the number 15, and then enter, you will jump to the 15th line of the article.

  • Find characters

    "/keyword": First press the "/" key, and then enter the character you want to look for, if the first keyword is not what you want, you can always press "n" will look back to the keyword you want.

    "? keyword": Press "?" first Key, and then enter the character you want to find, if the first keyword is not what you want, you can always press "n" will look forward to the keyword you want.

  • Save File

    "w": Enter the letter "w" the colon to save the file.

  • Leave VI

    "q": Press "q" is to exit, if you cannot leave VI, can be "q" followed by a "!" Forced to leave VI.

    "wq": Generally recommended to leave, use with "w", so you can also save the file when exiting.

     

Linux Learning Notes (4)-Use of the text editor 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.