The vi editor is a text tool that processes ASCII data. Most linux distributions have already installed the vi editor by default. Vi is short for visual interface. vim is visual interface improved (enhanced version) vi. By default, vim supports Code commands to highlight, making the text easier to understand. Vi has two types of configuration files: The global configuration file/etc/vimrc, which takes effect for all users. The other is the user configuration file, which needs to be manually created, such as touch ~ /. Vimrc is created in the user's home directory and is created as a hidden file. The settings here only apply to the current user.
1. Switch between vi Mode and Mode
Vi has three modes: command mode (edit mode), Insert mode (Insert mode), and last line mode (last line mode, shows the relationship between modes:
Vi is the editing mode by default, and the editing mode cannot perform any write operations on the text.
(1) edit mode ----> input mode: You can perform the following operations:
Directly Type I: insert to convert the current cursor to the input mode.
I: Switch to input mode at the beginning of the row where the current cursor is located
A: append, which converts the character behind the current cursor to the input mode.
A: Switch to input mode at the end of the row where the current cursor is located
O: Creates a blank row under the row where the current cursor is located and converts it to the input mode.
O: Create a new row above the row where the current cursor is located and convert it to the input mode.
(2) input mode -----> edit mode:
Press Esc on the keyboard.
(3) edit mode -----> last line mode
Type:
(4) Last line mode -----> edit mode
Press Esc twice in a row
2. Operations in the editing mode
(1) jump of the cursor:
A) jump between characters with the cursor
H: left # h jump to left # characters
L: Right
J: Bottom
K: Upper
B) jump between words with the cursor
W: the beginning of the last word
E: jump to the end of the current or next word
B: Jump to the beginning of the current or previous word
C) jump the cursor between sentences
): Next sentence
(: Previous sentence
D) jump between paragraphs with the cursor
}: Next section
{: Previous paragraph
E) jump between lines with the cursor:
1G, gg: Jump to the beginning of the line
G: End of a row
# G: Row n, # indicates the number of rows
F) jump the cursor in the row:
^: The first non-blank character at the beginning of the line
$: End of the absolute line
0: Beginning of the absolute line
(2) screen flip
Ctrl + f: Turning a screen at the end of the file is equivalent to Pagedown.
Ctrl + B: Flip a screen to the first part of the file to operate on Pageup
Ctrl + d: half screen to the end of the file
Ctrl + u: half screen to the first part of the file
(3) copy operation, also called y (yank) Operation
Yy: indicates the row where the cursor is copied.
# Yy: indicates that the copy operation includes the row where the cursor is located and the following # Rows, # indicates numbers
Y $: copy the cursor to the end of the row
Y ^: indicates that the cursor is copied to the beginning of the row.
(4) The paste operation is also called the p (paste, put) operation.
The whole row is copied:
P: paste it below the row where the current cursor is located;
P: paste above the row where the current cursor is located
The whole row is not copied:
P: paste the character behind the current cursor;
P: paste the character in front of the current cursor;
(5) Delete (x, d)
X: delete a single character behind the cursor
# X: delete # characters after the cursor, # representing numbers
Dw: delete the word with the cursor
Db: delete words before the cursor
De: delete the word after the cursor is located.
D ^: delete all character words before the cursor
D $: delete all character words after the cursor
Dd: Delete the entire row where the cursor is located.
# Dd: Delete the rows that contain the cursor. # It indicates a number.
(6) cancel the operation
If you cancel a previous failed operation, you can press the u key to cancel the previous operation. By default, you can recall the previous 50 operations. If you think the previous Undo operation also needs to be undone, press the crtl + u key to undo the operation.
(7) search operation. Enter/or? In editing mode ?, Then you can find the characters
/Keyword: Search for the end of the file from where the current cursor is located
? Keyword: searches for the file header from where the current cursor is located
N: Next, in the same direction as the SEARCH Command
N: the first one, opposite to the query command
3. Operations in input mode
When you type (I, I, a, A, o, O) in editing mode, the words "-- INSERT --" will appear below the file, indicating that the file is in input mode, the input mode directly enters any character into the file.
4. operations performed in the last row Mode
(1) Save and exit operations
: W save
: Q exit
: X save and exit
: All the walls are saved. Generally, applications can open multiple pages at the same time.
: Qall exits. Generally, Applications open multiple pages at the same time.
: W! Force save
: Q! Force exit
: Wq! Force save and exit
: X! Force save and exit
(2) The delete operation can be performed in the last row mode and can be bounded.
Start row in syntax format and end row d
:. Indicates the row where the current cursor is located
: 1 indicates the first line
: # Indicates the # Row, # indicates the number
: $ Indicates the ending row.
: % Indicates the entire text
: 1, $ d Delete the first row to the last row
:. $ D Delete the current cursor until the oldest row
: % D Delete the entire text
: 1, + 3d Delete the first line and the third line after, the first line also includes, so it is to delete four lines
(3) search operations. The search operations are the same as those in edit mode. mode matching is supported.
/Keyword: Search for the end of the file from where the current cursor is located
? Keyword: searches for the file header from where the current cursor is located
N: Next, in the same direction as the SEARCH Command
N: the first one, opposite to the query command
(4) modify and replace operations, and also support pattern matching
Syntax format
: Address demarcation s/search mode/content replaced with/gi
/Indicates the delimiter, which can be a match between @, #, and other special easy-to-distinguish characters.
G global, I ignore is case insensitive
Eg:
Delete the beginning of a line #: % s @ ^ # @ Delete the beginning of the line # and followed by a blank character;: % s @ ^ #[[: space:] * @ add #;: % s @ ^ [[: space:] to change down to up;: % s @ down @ up @ g add #;: 1, 10 s @ ^ @ # @ g at the beginning of the row in the specified range
5. Window attribute definition. In the last line mode: (enter the set command in the last line mode to view the Help Command of the set .)
Show row number:
Set nu
Set nonu
Automatic indent:
Set autoindent, set ai
Set noai
Case Insensitive
Set ignorecase, set ic
Set noic
Show matching brackets
Set showmatch, set sm
Set nosm
Syntax coloring
Syntax on
Syntax off
Search highlighted
Set hlsearch
Set nohlsearch
You can directly write the properties defined in the window to the vim configuration file.
6. Other vim support
(1) vim visualization Mode
Visual Mode
V: select the character that the cursor crosses.
V: select the row with the cursor and select the whole row.
Esc and Esc: Return to editing mode
(2) split a document window:
Ctrl + w, s: horizontal segmentation Ctrl + w, arrows (up and down), indicating Switching
Enter q in the last row mode to exit
Ctrl + w, v: vertical segmentation Ctrl + w, arrows (left and right), indicating Switching
Enter q in the last row mode to exit
======= The knowledge learned by the blogger comes from the hands-on Teacher Ma Ge ======
Marco education's "2014 summer camp" has begun !!! Mago education is currently the most cost-effective Linux training, ranking first in the country, and known as the "Whampoa Military Academy" in the Linux field by netizens. All the courses are explained using Centos6.5x86 _ 64, after summing up and refining several network classes, the course system has been gradually improved. The students' learning progress is monitored and the quality test system tests the students' mastery, active online Q & A sessions, accompanied by famous teachers, you can't miss it.
Details DASH: http://www.magedu.com/
Course: http://www.magedu.com/mentuqc
Network Class integration service: http://mageedu.blog.51cto.com/4265610/1379598
Contact: customer service QQ 2813150558 customer service QQ 1661815153
========================================================== ====