1. Introduction of VI
basically , VI is divided into three modes:
Command mode
Open a file with VI directly into the command mode. In this mode, you can use [up or down ] keys to move the cursor, delete characters to process the contents of the file, or copy and paste the file data.
insertion Modes (insert mode)
in command mode, enter: [i Ia A o O] any one letter will go into insert mode. This is where you can edit your files.
I: enter before the current cursor is positioned.
I: Enter at the beginning of the current cursor position.
A: Enter after cursor position
A: Enter at the end of the cursor line
O: add a blank line to the next line where the cursor is located
O: Add a blank line to the previous line where the cursor is located
command-line modes (command-line mode)
in command mode, enter [:/ ?] Either way, you can do the command-line mode.
So how do you get out of VI ?
if it is in insert mode, then type " ESC"key, enter
: q! force exit, i.e. do not save exit
: Wq Save Exit
: Wfilename Save File
: x Save and exit
If you are in command-line mode, directly enter ZZ, that is, to save the exit .
2. VI use
1. Key instructions
Key instructions in command mode:
Move Cursor |
h or left ARROW key The cursor moves one character to the left |
J or down ARROW key move the cursor down one character |
K or Up ARROW key move the cursor up one character |
L or RIGHT ARROW key The cursor moves one character to the right |
if you want to make multiple moves, such as moving down column, you can use 30j The combination button |
"Crtl "+ "F " The screen moves down one page, which is equivalent to page DOWN the key |
"Crtl "+ "b " The screen moves up one page, which is equivalent to "page UP the key |
the Ctrl "+ "D " The screen moves down half a page |
the Ctrl "+ "U " The screen moves up half a page |
N "Space " move the cursor to the right n of characters |
0 move to the beginning of the line where the cursor is located |
$ move to the end of the line where the cursor is located |
G move the last line of this file |
NG move to the nth of this file Line |
GG move to the first line of this file |
N the Enter " move cursor down n Line |
W jump to the beginning of the next word |
b jump to the beginning of a previous word |
e jumps to the ending of the current or next word |
search and replace |
/key look under the cursor for key this keyword |
?key look for key this optical key |
use /key mate N or N search down the next keyword n Search up next keyword |
:n1,n2s/word1/word2/g Replace |
:1,$s/word1/word2/g from the first line to the last line to find word1 and use word2< /c10> Replacement s///GCI g: Lock All the found content C: Human Interaction I: Ignore Case among them, in order to avoid the problem of escaping,/ can be used @,# and other symbols instead. |
Delete, copy and paste |
x,x in a row, x to remove a character backwards, X to delete a character forward |
#x # for numbers, continuous backward removal # of characters |
DD Delete the line where the cursor is located |
#dd Delete cursor down # Line d0 d^ d$ DG wait |
yy Copy the row where the cursor is located |
#yy the copy cursor is located down # Line |
P Paste |
u Revoke |
"Crtl "+ "R " revocation of previous revocation |
2. Vim Visualization mode
To enter v in command mode, manual select Mode is available.
V: The selected cursor is the same as the forward
Once selected, the previous edit commands can be used
3. Open multiple Files
: Next Next
: Prev Previous
: First One
: Last One
For easy comparison, you can use the –o or-o option
Vim–o: Horizontal Screen comparison
Vim–o: Vertical Screen comparison
How do I move the cursor in two files?
Horizontal screen comparison using the "Crtl" +w up and down arrows
Vertical screen comparison using "Crtl" +w left and right arrows
In the same file, you can use a split screen to compare the differences
Horizontal split with "Crtl" +w,s
Vertical split with "Crtl" +w,v
4. Vim's environment setting parameters
: Set Nu Set line number |
: Set Nonu Cancel Line number |
: Set AI Auto Indent |
: Set IC Ignore Case |
: Set SM display the symbol that matches it |
: Syntax on Syntax Highlighting |
: Set Hlsearch Search Highlighting |
: Set Autoindent Auto Indent |
This article is from the "Midgard Inn" blog, please be sure to keep this source http://fckz001.blog.51cto.com/11636733/1906261
Use of the Linux base vim