Introduction to the use of the Editor VI under Linux

Source: Internet
Author: User

The VI Editor is the standard editor for all UNIX and Linux systems. The vi Editor is exactly the same for any version of UNIX and Linux systems .

Basically, vi can be divided into three states , namely the command mode (commandmode), insert mode (inserts) and the bottom line mode, the function of each mode is:

Command mode: Controls the movement of the screen cursor, deletion of characters, words or lines, moving and copying a section and entering insert mode, or to last line mode.

Insert mode: Only under Insert mode, you can do text input, press "ESC" key to return to command line mode.

Bottom-line mode: Keep or exit VI, or you can set the editing environment, such as searching for strings, listing line numbers ... such as

Open terminal, specify to a directory, enter VI TESTVI, that is to open with VI file name TESTVI, if there is no such file in this directory, will automatically create an empty TESTVI file, this time will go to the VI Full Screen editing screen ( Note: A wave symbol is displayed before each line to indicate that the behavior is blank line). After entering VI, is in "command mode", to switch to "insert mode" to enter text.

from the command mode into the insert mode to edit the file : in "command mode" click the lowercase letter "I", "a", "O" can enter "Insert mode", this time you can start to enter the text.

enter into command mode by insert or bottom line mode : Press ESC.

enter into the bottom line mode by the command mode : Press ":" Key.

enter into insert mode by the bottom row mode : Click the lowercase letter "I", "a", and "O" to enter "Insert Mode".

Exit VI and save the file : in the bottom row mode, enter:

(1), W testVi1 (save Testvi Modified file as TestVi1, at this time the content of TESTVI is still the original content, TESTVI did not make any changes);

(2), Wq (Save the modified Testvi file and exit VI);

(3), q!  (or Q) (without saving the modified Testvi file Exit VI, the contents of the Testvi file are still the original file before opening).

When entering insert mode from the command mode:

(1), press "I" key, is the beginning of the cursor from the current position to enter text;

(2), press "A" key, is the current cursor position from the next position to start typing text;

(3), press "O" key, the next line of the current cursor to insert a new line, starting from the beginning of the input text.

To move the cursor in command mode :

(1), the lowercase letter "K", "J", "H", "L" respectively control the cursor to move to a line on the cursor, move to the next line of the cursor, move to the left of the cursor text, move to the right of the cursor to a text;

(2), "Ctrl+b", "ctrl+f" respectively to display the previous page content, the next page content;

(3), "Ctrl+u", "Ctrl+d" respectively for the display of the contents of the upper half of the page, the next half of the content;

(4), by the number 0 (or "^"), "$", respectively, moved to the beginning of the line of the cursor, the end of the line;

(5), press "$", move to the end of the line where the cursor is located;

(6), by the capital letter "G", move to the end of the file; if you press a "number" and then the capital letter "G", the cursor moves to the beginning of the first "number";

(7), press "W", "E", the cursor jumps to the next word (word) of the word head, the next word (word) of the end;

(8), press "B", the cursor jumps to the last word (word) of the word head;

(9), press "#", search up the current cursor pointing to the word.

Delete text in command mode :

(1), each press the lowercase letter "x", delete the next character in the position of the cursor;

(2), each press the capital letter "X", delete the position of the first character of the cursor;

(3), Press two times in a row lowercase letter "D", delete the line of the cursor.

copy in command mode :

(1), by the lowercase letter "yw", the cursor is located at the end of the character to copy into the buffer;

(2), press the lowercase letter "p" to paste the characters in the buffer into the position of the cursor.

restore the last action in command mode : If you perform an incorrect operation, you can revert to the previous operation by pressing the lowercase letter "U".

to jump to the specified line in command mode :

(1), press "Ctrl + G", the last line of the current page shows the line number of the line where the cursor is located;

(2), press "a number + G", which means moving the cursor to the beginning of the "one number" line of the file.

Bottom Line mode The following travel numbers : enter "Set Nu", and after carriage return, the line number is listed before each line in the file.

skip to the line specified in the file in the bottom row mode : Enter a number after the colon (:), and then press ENTER to jump to that line.

find characters in the bottom row mode :

(1), 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 the lowercase letter "n" Key will be back (by the capital letter "n" Key will go forward) to find the keyword you want until;

(2), first press "?" Key, and then enter the character you want to look for, if the first time you find the keyword is not what you want, you can always press the lowercase letter "n" Key will go forward (by the capital letter "n" key will be back) to find the keyword you want.


Some of the vi settings (such as statement highlighting, etc.), refer to http://blog.chinaunix.net/uid-10638908-id-2944538.html:

(1), Input: VI ~/.VIMRC; If not, it will be created;

(2) The contents of the VIMRC file are:

Syntax onset tabstop=4set softtabstop=4set shiftwidth=4set autoindentset cindentset cinoptions={0,1s,t0,n-2,p2s, (03s, =.5s,>1s,:1s}set Nuset Hlsearch

(3), save VIMRC file, when you open another file with VI, if prompted sorry, the command is not available in Thisversion:syntax enable press ENTER Ortype Comm And to continue, you need to install VIM, the input command is: sudo apt-get install vim;

(4), and then use VI to open the file, there will be highlighting and other related characteristics.


Introduction to the use of the Editor VI under Linux

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.