Centos vi usage

Source: Internet
Author: User
The operating vi editor is a standard editor for all Unix and Linux systems. it is not inferior to any latest text editor, here is just a brief introduction to its usage and a small part of commands. The vi editor is identical for any version of Unix and Linux systems, so you can learn more about it in any other section about vi. Vi is also the most basic text editor in Linux. after learning it, you will be able to enjoy the free access in the Linux world. 1. vi Vi editor usage
The vi editor is a standard editor for all Unix and Linux systems. it is not inferior to any of the latest text editors. here we just briefly describe its usage and
A small part of commands. The vi editor is identical for any version of Unix and Linux systems, so you can learn more about it in any other section about vi.
Vi is also the most basic text editor in Linux. after learning it, you will be able to enjoy the free access in the Linux world.
1. basic concepts of vi
Basically, vi can be divided into three states: command mode, Insert mode, and last line mode ),
The functions of each mode are as follows:
1) command Line mode)
Controls the movement of the screen cursor, the deletion of characters, words or rows, and the movement of a segment to an Insertmode or to lastlinemode.
2) Insert mode)
You can enter text only in Insertmode. press ESC to return to command line mode.
3) baseline mode)
Save the file or exit vi. you can also set the editing environment, such as searching strings and listing row numbers ...... .
However, we generally simplify vi into two modes in use, that is, the last line mode is also included in the command line mode ).
2. basic operations of vi
A) go to vi
After the system prompts you to enter the vi and file name, you will be taken to the vi full screen editing screen:
$ Vimyfile
Note that after you enter vi, you are in commandmode. you need to switch to Insertmode )」
To input text. People who use vi for the first time will want to move the cursor first with the upper and lower right keys. as a result, the computer keeps beeping and getting angry with themselves. so after entering vi, do not
Switch to "Insertmode!
B) switch to Insert mode to edit the file
Click "I" under "commandmode" to enter "Insertmode". then, you can enter the text
.
C) Insert switchover
You are currently in "Insertmode", and you can only enter text all the time. if you find that you have entered an error! If you want to move back with the mouse button, you need to delete the word.
Press ESC to go to commandmode and then delete the text.
D) exit vi and save the file
Under commandmode, click the ":" colon to enter Lastlinemode. for example:
: Wfilename (enter "wfilename" to save the article with the specified file name filename)
: Wq (enter "wq" to save the disk and exit vi)
: Q! (Enter q !, Force exit vi without saving the disk)
3. command mode function key
1) in insert mode, press "I" to switch to insert mode "insertmode", and press "I" to enter insert mode. then, the input file starts from the current position of the cursor;
After you press "a" to enter the insert mode, the text is entered starting from the next position where the cursor is currently located;
After you press "o" to enter the insert mode, a new row is inserted and text is entered from the beginning of the line.
2) switch from Insert mode to command line mode
Press ESC.
3) move the cursor
Vi can be moved up, down, left, and right directly with the cursor on the keyboard, but the regular vi uses lowercase letters "h", "j", "k", and "l 」, control the cursor,
One cell to the right.
Press ctrl + B to move the screen to the back.
Press ctrl + f to move the screen to the front.
Press ctrl + u to move the screen to the rear half of the page.
Press ctrl + d to move the screen to front.
Press the number "0": to move to the beginning of the article.
Press G to move to the end of the article.
Press "$" to move to "end of line" of the row where the cursor is located ".
Press ^ to move to the first row of the row where the cursor is located"
Press w to jump to the beginning of the next word
Press "e": Move the cursor to the end of the next word
Press "B": the cursor returns to the beginning of the previous word
Press # l to move the cursor to the # position of the row, such as 5l and 56l.
4). delete text
"X": deletes the "next" character at the cursor position every time you press it.
"# X": for example, "6x" indicates deleting the "next" to the cursor position.
"X": uppercase X. each time you press it, the "front" character of the cursor is deleted.
"# X": for example, "20X" indicates to delete the "front" of the cursor.
Dd: delete the row where the cursor is located.
「 # Dd 」: delete from the row where the cursor is located # row
5). copy
"Yw": Copy the character at the end of the cursor to the buffer zone.
# Yw: Copy # words to the buffer zone
"Yy": Copy the row where the cursor is located to the buffer zone.
"# Yy": for example, "6yy" indicates copying 6 lines of text from the row where the cursor is located "down.
P: place the characters in the buffer to the cursor position. Note: all copy commands related to "y" must work with "p" to complete the copy and paste function.
6). replace
"R": replace the character at the cursor position.
"R": replace the character wherever the cursor goes until you press the "ESC" key.
7). reply to the previous operation
"U": if you mistakenly execute a command, you can immediately press "u" to return to the previous operation. You can perform multiple replies for multiple times by "u. 8). change
"Cw": change the word at the cursor to the ending point.
"C # w": for example, "c3w" indicates that three words are changed.
9). jump to the specified row
Ctrl + g lists the row numbers of the cursor.
"# G": for example, "15G" indicates moving the cursor to the first row of the article.
4. Introduction to commands in Last line mode
Before using lastlinemode, remember to press ESC to confirm that you are already in commandmode, and then press: to enter lastline
Mode 」.
A) list row numbers
"Setnu": After "setnu" is entered, the row number is listed before each row in the file.
B) jump to a row in the file.
"#": "#" Indicates a number. enter a number after the colon and press enter to jump to the row. for example, enter the number 15 and press enter, will jump to
15 rows.
C) search for characters
"/Keyword": First press the "/" key and then enter the character you want to search. if the first search keyword is not what you want, you can always Press "n" to find your desired
Keyword.
「? Keyword: First press 「?」 Enter the character you want to search for. if the keyword you want for the first time is not what you want, you can press "n" until you find
Keyword.
D) save the file
"W": Enter "w" in the colon to save the file.
E) leave vi
Q: Press q to exit. if you cannot exit vi, you can follow q with 「!」 Force exit vi.
"Qw": it is generally recommended to use it with "w" when leaving, so that files can be saved when exiting.
5. vi command list
1. the following table lists some key functions in command mode:
H
Move the cursor one character left
L
Move the cursor one character to the right
K
Move the cursor up a row
J
Move the cursor down a row
^
Move the cursor to the beginning of the line
0
Number "0", move the cursor to the beginning of the article
G
Move the cursor to the end of the article $
Move the cursor to the end of the row
Ctrl + f
Forward screen flip
Ctrl + B
Flip back
Ctrl + d
Front half screen
Ctrl + u
Flip back half screen
I
Insert characters before the cursor position
A
Add the next character at the cursor position
O
Insert a new row and start from the beginning of the row.
ESC
Return from input to command status
X
Delete characters after the cursor
# X
# Characters after deleting the cursor
X
(Uppercase X), delete the character before the cursor
# X
Delete # characters before the cursor
Dd
Delete the row where the cursor is located
# Dd
Delete # rows from the number of rows where the cursor is located
Yw
Copy a word at the cursor position
# Yw
Copy the # characters at the cursor position
Yy
Copy a line at the cursor position
# Yy
Copy the number of rows from the cursor
P
Paste
U
Cancel operation
Cw
Change a word in the cursor position # cw
# Words for changing the cursor position
2. some commands in the following table Travel command mode
Wfilename
Save the file being edited as filename
Wqfilename
Save the file being edited as filename and exit vi
Q!
Discard all modifications and exit vi
Setnu
Show row number
/Or?
Search, enter the content to search after/
N
And/or? If the search content is not the keyword, press n or backward (and/) or forward (and? Continue searching until it is found.

 

 

Note the following when using vi for the first time:

1. after opening a file with vi, it is in command mode. you must switch to Insert mode to enter text.
Switch method: Click "I" under "command mode" to enter "Insert mode". then you can
Enter the text.
2. after editing, you must switch from the insert mode to the command line mode to save the file. to switch to the mode, press ESC.
3. save and exit the File: In command mode, enter wq! (Don't forget the one before wq :)
Related Article

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.