Linux full-screen text editor VI use instructions basic tutorial

  
 

vi is a full-screen text editor for all Linux systems that provides a window device through which files can be edited. However, since our general users are initially exposed to Microsoft products, it is not similar to the use of EDIT under DOS and Notepad under Windows. Therefore, beginner Linux users find it difficult to use vi, even I can't start, let me introduce you to the use of vi. +++++++++++++++++++++++++++ The basic concept of ++++++++++++++++++++++ ++++++++++++

Basic vi can be divided into three operational states: Command mode, Insert mode, and bottom line command mode (Last). Line mode), the function of each mode is divided as follows: 1. Comand mode: Controls the movement of the screen cursor, the deletion of characters or cursors, moves a certain section and enters the Insert mode, or goes to the Last line mode. 2. Insert mode: Only in the Insert mode, you can do text data input, press Esc, etc. to return to the Comand mode. 3. Last line mode: will save the file or leave the editor, you can also set the editing environment, such as looking for strings, listing line numbers, and so on. However, you can simplify vi into two modes, that is, calculate the Last line mode into Command mode and divide vi into Command and Insert mode.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++

Enter vi

Enter vi and file name in the system prompt symbol, you can enter vi full screen editing Picture: $vi testfile has a special point to note, that is, after you enter vi, you are in "Command mode", you have to switch to Insert mode to enter text. Users who use vi for the first time will want to use the up, down, left and right keys to move the cursor. As a result, the computer
is always called, and it is half dead, so after entering vi, don't tamper with it, and then switch to Insert. Switch to the Insert mode to edit the file. In Command mode, press ‘i’,‘a’ or ‘o’ three keys to enter the Insert mode. At this point you can start typing text. i: Insert to insert the entered text from where the cursor is currently located. a: Increase, the current word where the cursor is located starts to input text. o: Insert a new line and enter text from the beginning of the line. Insert mode to Command mode, press Esc and you are currently in Insert mode, you can only type all the time. If you find that you have typed a typo, you want to use the cursor keys to move back and delete the word. Press ESC to switch back to Command mode and delete the text.

Leaving vi and saving files

In Command mode, type "Last line mode", for example::w filename (enter “w filename”, in the command mode) The article is stored in the specified file name filename):wq (enter “wq”, because the file name testfile has been specified at the time of entry, so it will be written to testfile and leave vi):q! (enter “q!”, force Leave and abandon the edited file)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++

After introducing the command mode command, the instruction is followed by “common” The function key of the word indicates the more commonly used vi command. Please readers must learn and remember. (1) I, a, o switch into Insert mode. [Super commonly used] (2) Move the cursor vi can directly use the cursor keys on the keyboard to move up and down, left and right, but the regular vi is to use the lowercase English letters h, j, k, l to control the cursor left, bottom, top and right respectively. Move one space. Press Ctrl+B: the screen moves back one page. [Common] Press Ctrl+F: The screen moves forward one page. [Common] Press Ctrl+U: The screen moves half a page backward. Press Ctrl+D: the screen moves forward by half a page. Press 0 (number zero): to move the beginning of the article. [Common] Press G: to move to the end of the article. [Common] Press w: The cursor jumps to the beginning of the next word. [Common] Press e: The cursor jumps to the end of the next word. Press b: the cursor returns to the beginning of the previous word. Press $: to move to the end of the line where the cursor is located. [Common] Press ^: to move to the first non-blank character on the line. Press 0: to move to the beginning of the line. [Common] Press #: to move to the #th position of the line, for example: 51, 121. [Common] (3) Delete text x: Each time you press to delete the next character at the cursor position. [Ultra-Frequent] #x: For example, the 6x table deletes the last 6 characters of the cursor position. [Common] X: X of a large character, each time the cursor deletes the previous character at the position of the cursor. #X: For example, the 20X table deletes the first 20 characters of the cursor position. Dd: Delete the line where the cursor is. [Ultra-Frequency] #dd: For example, the 6dd table deletes the text from the line where the cursor is located, down to 6 lines. [Common] (4) Copy yw: Copy the character from the cursor to the end of the character into the buffer. (I want to reverse the function of #x, #X) p: Paste the characters in the buffer to the position of the cursor (instructions & lsquo;yw’ and ‘p must be used together). Yy: Copy the line where the cursor is. [Ultra-Frequency] p: Copy a single line to where you want to paste. (Instructions & lsquo;yy’ and ‘p’ must be used together) #yy: For example: 6yy means copying the text from the line where the cursor is located, 6 lines down. [Common] p: Copy multiple lines to where you want to paste. (Instructions & lsquo; #yy & rsquo; & & lsquo; p & rsquo; must be used together) "ayy: put the copy line into the buffer a, vi provides the buffer function, the commonly used data exists in the buffer "ld:; ap: will be placed in the buffer a data Paste. “b3yy: store three rows of data in buffer b. “b3p: paste the data of buffer b (5) instead of r: replace the character where the cursor is located: [common] R: replace the character until you press Esc. (6) Restore (undo) the previous command u: If you mistakenly manipulate an instruction, you can immediately press u to return to the previous operation. [Ultra-common].: English point <;” can repeat the previous instruction. (7) Change cw: Change the word where the cursor is located to the end of the $. c#w: For example, c3w represents a change of 3 words. (8) Jump to the specified line Ctrl+G: List the line number of the line where the cursor is located. #G: For example, 15G means moving the cursor to the beginning of the 15th line of the article. [Common]

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++

Before you use the Last line mode, please remember to press the Esc key to confirm that you are in Command mode. Then press the colon “:” or “/” or “? ” One of the three keys enters the Last line mode. 1. List the line number set nu: After entering “set nu”, the line number will be listed before each line of the article. 2. Jump to a line of the article #: The pound sign represents a number, enter the number before the Last line mode prompt ““:”, then press Enter to jump to the line.

Copyright © Windows knowledge All Rights Reserved