RHCE path -- vi editor usage

Source: Internet
Author: User
For vi usage, let's first talk about the text editor and word processing software Text Editor: in windows, the text editor is mainly for notepad in Linux, there are many text editors, such as nano, emacs, in windows, the vi processing software mainly includes office, wps, and wordpad. in Linux, the first system administrator, such as openOffice, has at least one text processor on the command line interface for management.

Vi usage

Let's talk about the text editor and word processing software.
Text Editor:
In windows, the text editor is mainly notepad.
In Linux, there are many text editors, such as nano, emacs, and vi.
Word Processing Software
In windows, there are mainly office, wps, and WordPad
In Linux, there are mainly openOffice and so on.

The first system administrator should have at least one command line interface text processor to manage the daily work of the system.
There are a lot of text management tools, but we recommend that you use the regular and common word processor vi, because vi exists in almost any unix-like machine and learns about it, it will be much easier. Now vi has the advanced vim
With the version, there are many more available functions than vi. vi is an important tool for shell programming and server configuration. Therefore,
Be sure to learn well.

VI is designed to replace all the operations with the keyboard. Therefore, we can complete all the operations of Text Processing without the mouse.

Do you still remember what a plain text file is? It is a file mainly based on ascii code, no matter which editor is used to open it like this
You can see the content without Garbled text.

In any case, to learn Linux well, you must manually configure text files, and vi is the best tool.
The following describes how to use vi.

When using vi, you need to know the three modes of vi, and these three modes can be switched freely.
1. General mode: In this mode, press the I, a, o, and other keys to enter the editing mode. Press esc to return
Back to normal mode.
Press: Key to enter the command mode.
2. edit mode: In this mode, Press esc to return to normal mode.
3. Command mode: In command mode, you cannot directly enter edit mode.

The following describes the functions of these modes.
1. General mode: move the cursor, search, replace, delete characters, delete the entire line, copy the entire line, and paste the entire line.
2. editing mode: In this mode, you can enter any character, just like in windows notepad.
3. Command Line Mode: read, store files, and other additional functions.

How to save files?
In normal mode, press: wq to save and exit.

How to create a file?
Enter the file name directly after vim in the command line. For example
Vim test.txt
A test.txt file is created under the current directory.

For example, the test.txt file can be created, which is very simple. Note that if the File Permission is incorrect, the file may not be written. You can use "Force write" to use ": wq !", Save and exit. Add one more
Exclamation point.


In normal mode: move the cursor
H or a direction key to the left: move the cursor to the left.
J or downward direction key: move the cursor down a character
K or up direction key: move the cursor up a character
L or right direction key: move the cursor one character to the right

If you want to move multiple times, for example, move 30 rows down, you can use "30j" or "30 downward direction key"
Add the number of times (number) You want to perform the operation.

Ctrl + f: Flip down
Ctrl + B: screen up
Ctrl + d: Flip down half screen
Ctrl + u: half screen up

+: Move the cursor to the next line without space characters
-: Move the cursor to the previous line without space characters
N : N indicates a number. For example, 21. Press the number and then press the Space key. The cursor will move the n characters in this line to the right, for example, 17. Then the cursor moves 17 characters behind it.
0: Move to the first absolute line of the row where the cursor is located, with spaces.
$: Move to the end of the row where the cursor is located.
H: move the cursor to the top line of the screen.
M: move the cursor to the center of the screen.
L: move the cursor to the bottom line of the screen.
G: Move to the last row of the file.
NG: n is a number and can be moved to the nth row of the file. For example, 20 GB will be moved to row 20th.
Gg: Move to the first line of the file.
NENTER: n number, move the cursor down n rows.

Normal Mode: Search and replacement.
/Word starts from the cursor and looks down for a string named word
? Word starts from the cursor and looks up for a string named word
N is an English button that indicates "repeat the previous search action". For example, if you search for a word string by executing/word, press n, will continue searching for the next string named word. If it is executed? If word is used, press n to search for a string named word.
N is the English key. N is the opposite of n. It performs the previous search action for "reverse". For example, after/word, press N to search for word "up ".


Normal Mode: Search and replacement

: N1, n2s/word1/word2/g n1, n2 is a number, search for word1 words in line n1 and line n2, and replace word1 with word2. For example: 2, 24 s/apple/banana/g is to find the word apple between the second row and the second row.
Replace it with banana.
: 1, $ s/word1/word2/g $ indicates the last row, so it is to search for word1 in row 1st and last and use word2
Replace word1.
: 1, $ s/word1/word2/gc is the same as above, but when you replace it, you are prompted whether to replace it.

Normal Mode: delete, copy, and paste.
In a row of characters, x deletes one character backward. X deletes one character forward.
Nx n is a number, indicating that n characters are deleted backward. For example, to delete 10 characters consecutively, enter 10 x
Dd deletes the whole line of the cursor.
Ndd n is a number. n rows are deleted from the cursor position.
D1G delete all data from the cursor position to the first row
DG deletes all data from the cursor position to the last row
D $ Delete the last character from the cursor position to the row
D0 d is followed by a number 0, removing the first character from the cursor position to the row
Yy copy the row where the cursor is located
Nyy copies n rows down from the row where the cursor is located.
Y1G copy all data from the cursor position to the first row
YG copies all data from the row where the cursor is located to the last row.
Y0: copy the cursor to the beginning of the row.
Y $ copy the cursor to the end of the row

Normal Mode: delete, copy, and paste
P P: paste the copied data to the next row in the row where the cursor is located. P: paste the copied data to the cursor.
The previous row
J. Combine the row where the cursor is located with the data in the next column into the same row
C. Delete multiple data records repeatedly. For example, delete 10 rows down.
U indicates the restoration of the previous operation.
Ctrl + r redo the previous operation

Normal Mode: delete, copy, and paste
. This is the decimal point, which means to repeat the previous action. If you want to delete or paste it again, press the decimal point.
: W save
: W! If the file is read-only, the file is forcibly written. However, whether the file can be written depends on the file permission.
: Q exit
: Q! If you have modified the file but do not want to save it, use it! To forcibly exit the file not stored
: Wq save and exit
: E! Restore the file to the original state.
ZZ does not modify the file, so it does not store and exits. If the file is modified, the storage exits.
: W [filename] stores the edited data as another file, similar to saving it as a new file.
: R [filename]: In the edited data, the data of another file in the poetry will be added to the file content of filename.
The cursor is behind the row.
:! After the command is temporarily removed from vi, return to the command mode and execute the command display result, for example, ":! Command ", that is
You can view the ls output file information in/home in vi.
: Set nu displays the row number. After the row is set, the row number is displayed in the prefix of the first row.
: Opposite to set nu, set nonu is the canceled row number.

Most of the above is the usage of vi. It is much easier to learn vi well.

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.