VI Word Processor

Source: Internet
Author: User

Use of VI
Basically, vi is divided into three modes, namely "General mode", "edit mode" and "command-line order Mode" three kinds!
The effects of these three modes are:

General mode: When a file is processed with VI, the file is a general mode when it is entered. In this mode, you can use the "up or down" button to move the cursor, you can use "delete character" or "Delete whole line" to process the contents of the archive, you can also use "copy, paste" to process your file data.

Edit mode: In the general mode can handle delete, copy, paste and so on action, but can't edit! Wait until you press "I, I, O, O, A, a, R, r" to enter the edit mode. Watch out! Usually in Linux, when the above letter is pressed, the words "INSERT or REPLACE" will appear in the lower left of the screen before any word can be entered into your file! If you want to return to normal mode, you must press the "ESC" button to exit edit mode.

Instruction column Command mode: In general mode, enter ": OR/or?" "You can move the cursor to the bottom row, in this mode,
can provide your "search data" action, and read, save, a large number of substitution characters, leave VI, display line number and so on the action is achieved in this mode!

example of simple execution
How do we use VI to create a file named Test.txt? It is also very simple, the whole step can be like this:
1. Use VI to enter the general mode;
[Email protected] ~]# VI test.txt

Direct input "VI file name" can enter the VI! As shown, the lower left corner also shows the current status of this file! If the new file will display [new file], if it is an existing file, it will show the current file name, number of lines and characters, for example: ""/etc/man.config "145L, 4614C"

2. Press I to enter the editing mode and start editing the text;
In the general mode, just press I, O, A and other characters, you can enter the editing mode! In the edit mode, you can find the –insert-in the lower left corner of the screen, that is, you can enter any character hint! At this time, the keyboard except for [ESC] This button, other keys can be regarded as the general input button, so you can make any edits! (Note: In VI, [tab] The result of this button is not the same as the result obtained by the space character, special emphasis! )

3. Press the [ESC] button to return to normal mode; Well, suppose I've given him the same style as the above, so how do I get out? Yes! That's right! Just press the [ESC] button for him! Immediately you will find the –insert– in the lower left corner of the screen is missing!

4. Press in the general mode: Wq after storage leave VI! OK, we want to archive, save and leave the command is very simple, enter ": Wq" can archive away! (Notice, press: The cursor will move to the bottom line!) You can then enter "Ls-l" after the hint character to see the test.txt file we just created!

As a result, your file Test.txt has been set up! It's simple! It is important to note that if your file permissions are incorrect, such as-r--r--r--, then you may not be able to write, can you use the "force write" method? OK! Use ": wq!" to add an exclamation point! However, you need to pay special attention to Yo! That is in the "your permission can change" situation can be set up! For the concept of permissions, please refer to the Linux file permissions concept!



Command Column content description
As mentioned earlier, the so-called command-line or command-mode is the time when the word "--insert--" or "--replace--" is not displayed in the bottom row. There are usually the following directives in the command column: (Note that when ":" is pressed, the cursor will automatically move to the bottom line of the screen!) )


General mode: How to move the cursor
h or LEFT ARROW key (←) The cursor moves one character to the left
J or DOWN ARROW key (↓) cursor moves down one character
K or Up ARROW key (↑) The cursor moves up one character
L or right ARROW key (→) The cursor moves one character to the right
If you want to move multiple times, such as moving down 30 lines, you can use the "30j" or "30↓" combination of keys, that is, plus the number of times you want to do (number), press the action!
[Ctrl] + [f] screen "down" to move one page, equivalent to [PAGE DOWN] key (common)
[Ctrl] + [b] screen "Up" move one page, equivalent to [PAGE UP] key (common)
[Ctrl] + [d] screen "down" move half page
[Ctrl] + [u] screen "Up" move half page
+ cursor moves to the next column of non-whitespace
-Cursor moves to the previous column of non-whitespace
N<space> that n means "number", for example 20. When you press the number and then press the SPACEBAR, the cursor moves the n characters of the line to the right. For example 20<space>, the cursor moves 20 character distances to the back.
0 This is the number "0": Move to the front of the line prompt (common)
$ move to the last face of this line prompt (common)
H cursor moves to the top row of this screen
M cursor moves to the middle of this screen line
L move the cursor to the bottom line of this screen
G move to the last line of this file (common)
NG N is a number. Move to the nth row of this file. For example 20G moves to line 20th of this file (mates: Set Nu)
GG moved to the first line of this file, equivalent to 1G Ah! Common
N<enter> N is a number. Move the cursor down n rows (common)

General mode: Search and replace
/word looks under the cursor for a string with the string name Word. For example, in the file search Vbird This string, you can enter/vbird! Common
Word looks for a string above the cursor with a string name of Word.
n this n is the English key. Represents the meaning of "repeating the previous search action". For example, if we have just executed/vbird to search for Vbird this string, then pressing N will continue to search down the next string named Vbird. If the Vbird is executed, then pressing N will continue to search for the string named Vbird!
n this n is the English key. In contrast to N, the previous search action for "reverse". For example/vbird, pressing N means "up" to search for Vbird.
: n1,n2s/word1/word2/g N1 and N2 are numbers. Look for the string word1 between N1 and N2, and replace the string with Word2! For example, search for vbird between 100 and 200 rows and replace it with Vbird: ": 100,200s/vbird/vbird/g". Common
: 1, $s/word1/word2/g look for the word1 string from the first line to the last line, and replace the string with Word2! Common
: 1, $s/word1/word2/gc look for the word1 string from the first line to the last line, and replace the string with Word2! and display the prompt character before the substitution to the user to confirm (conform) whether need to replace! Common

General mode: Delete, copy and paste on
x, x in a line of words, X is the backward deletion of a character (equivalent to the [Del] key), X is to delete a character forward (equivalent to [backspace] is the backspace bar) (commonly used)
NX N is a number that continuously deletes n characters backwards. For example, I want to delete the 10 characters in succession, "10x".
NX N is a number that continuously deletes n characters. For example, I want to remove 10 characters in a row, "10X".
DD Delete the entire column where the cursor is located (common)
NDD N is a number. Delete the down n column where the cursor is located, for example, 20DD to delete 20 columns (common)
D1G Delete all data from the first row of the cursor
DG deletes all data from the last row of the cursor
d$ Delete the cursor where the last character of the row
D0 that is 0 of the number, delete the cursor where it is, and the first character of the line
YY the line where the cursor is copied (common)
Nyy N is a number. Copy the down n column where the cursor is located, for example, 20yy to copy 20 columns (common)
Y1G Copy all data from the column to the first column of the cursor
YG Copy all data from the column to the last column of the cursor
Y0 Copy the character that contains the cursor to all data at the beginning of the line
y$ Copy the character of the cursor to all data at the end of the line
P, p p to paste the copied data on the next line of the cursor, and p for a row on the cursor! For example, I currently have the cursor on line 20th and have copied 10 rows of data. When P is pressed, the 10 rows of data will be affixed to the original 20 lines, i.e. 21 lines. But what if we press P? Then the original 20th Guild was pushed into 30 rows. Common
J combine data from the cursor column with the next column in the same column
C repeatedly delete multiple data, for example, delete 10 rows down, [10CJ]
U undo, restore the previous action. Common
[Ctrl]+r redo the last action.] Common
This u with [ctrl]+r is a very common instruction! One is recovery, the other is redo once ~ take advantage of these two function keys, your editor, hey! Very happy!
. Don't doubt it! This is the decimal point! To repeat the meaning of a previous action. If you want to repeat the deletion, repeat the paste, and so on, press the decimal point "." It's all right! Common

Enter edit mode
I, I insert: Inserts the input text at the current cursor where the existing text is backward, where I is "inserting from the current cursor," and I is "inserting at the first non-space character where the current row is located". Common
A, A is "insert from the next character where the cursor is currently located" and A is "start at the last character of the line where the cursor is located." Common
O, o This is the case of the English letter O. o Insert a new line at the next line where the cursor is currently located; o Insert a new line on the previous line where the cursor is currently located! Common
R, R replaces: R replaces the character where the cursor is located, and R will always replace the text of the cursor until ESC is pressed; (common)
Above these keys, in the lower left corner of the VI screen will appear "--insert--" or "--replace--" words. The action is known by the name!! Special attention is, we also mentioned above, you want to enter characters in the file, must be in the lower left corner to see Insert/replace to enter Oh!
ESC exits edit mode and returns to normal mode (common)

Instruction-column command mode
: W writes the edited data to the hard drive archive (common)
: w! If the file property is read-only, the file is forced to be written. However, in the end can write, or with you on the file permissions related Ah!
: Q leave VI (common)
: q! If you have modified the file, do not want to store, use! Do not store files for forced departures.
Note that the exclamation point (!) in VI, often has the meaning of "mandatory" ~
: Wq to leave after storage, if: wq! After forcing the store to leave (common)
: e! Restore the archive to its original state!
ZZ If the file has not changed, then do not store away, if the file has been changed, then store and leave!
: w [FileName] stores the edited data as another file (similar to a new file)
: R [FileName] in the edited data, read into the data of another file. The file "filename" will be added to the cursor row after the
: n1,n2 w [filename] stores the contents of N1 to N2 as the filename file.
:! Command temporarily leaves VI to command column mode to perform command display results! For example ":! Ls/home "You can see in VI the file information under/home with LS output!
: Set NU Displays the line number, which, when set, displays the line number of the row in the prefix of each row
: Set Nonu is the opposite of Set Nu, the line number is canceled!

Block Selection (Visual block)
Key meanings of block selection
V character selection, the cursor will pass through the place of the white selection!
V-line selection, the line of the cursor will be reversed white selection!
[Ctrl]+v block selection, you can select the data in a rectangular way
Y Copy the anti-white place.
D Remove the anti-white place

Multi-file editing
Keys for multi-file editing
: N Edit Next file
: N Edit Previous file
: Files lists all the files that are currently open for this vim

key functions in multi-window cases
: SP [filename] opens a new window, if it has a filename, indicates that a new file is opened in a new window, otherwise two windows are the same file content (synchronized display).
[The CTRL]+WJ button is pressed by pressing [Ctrl], then pressing W and then releasing all the keys, and then pressing J, the cursor can be moved to the window below.
[Ctrl]+wk Ibid, but the cursor moves to the window above.
[Ctrl]+wq is actually: Q End left! For example, if I want to end the window below, then use [CTRL]+WJ to move to the lower window, press: Q to leave, you can also press [CTRL]+WQ Ah!]

VI Word Processor

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.