Vim is a well-known, powerful, highly customizable full-screen text editor similar to VI.
Usage: VIM [parameters] [file:] Edit the specified file
Or: Vim [parameters]-read text from standard input (stdin)
Or: Vim [parameter]-T tag edit file at tag definition
Or: Vim [parameter]-Q [errorfile] Edit the file at the first error
The working modes are:
- Edit mode: Command mode
- Input mode
- Last-line mode
Conversion between modes:
Edit mode > Input mode can be converted by the following letters:
I:insert,
A:append,
O:new line, switch to new row input
I: The beginning of the line
A: End of line
O (uppercase): New CCB above
Input mode > Edit mode:
ESC key
Edit mode > Last line mode:
: Key
Last-line mode > Edit mode:
ESC key
Open VIM:
# VIM
# Vim/path/to/somefile
+#: #为行号;
+/pattern
Turn off VIM:
: Q exit
: q! does not save exit
: Wq to exit after saving
: X Save exit
ZZ: Save exit
Cursor Jump (edit mode):
Jump between characters:
H: The left character of the current cursor
L: The right character of the current cursor
J: The next character of the current cursor
K: The previous character of the current cursor
Jump between words:
W: The first word of the word
E: The ending of the current or subsequent word;
B: The first word of the current or previous word;
In-line jump:
^: jumps to the first non-whitespace character at the beginning of a line;
0: Jump to the beginning of the line;
$: Jump to end of line;
Move between rows:
#G: #表示第几行
1G, GG: First line
G: Last line
Move between sentences:
): First sentence
(: End of sentence
Move between paragraphs:
}: Segment Header
{: End of paragraph
Edit command:
Character editing:
X: Delete the character at the cursor location
#x: Delete the current cursor backward (#) characters
XP: The current character is exchanged with a character after it
R: replaces the character at which the cursor is located;
Delete command:
D:
d^: Deletes the contents of the current cursor at the beginning of the sentence.
d$: Deletes the contents of the current cursor at the end of the sentence.
D0: Same as d^
DW, DE, DB
DD: Delete entire row
Note: The deleted content will be saved to the buffer by the Vim editor;
Paste: P (paste, put)
If this copied or deleted content is not a full line
P: Paste at the back of the current cursor;
P: Paste at the front of the current cursor;
If the copied content is a full row (more than one line)
P: Paste below the line where the current cursor is located;
P: Above line;
Copy command: Y, yank
Y
y$, y^, y0: Usage basic and delete same
Ye, yw, yb
YY: Copying rows
Changing the command: C, change
C $, c^, C0
CB, CE, CW
Cc:
To undo a previous edit operation:
U:undo: Undo the previous edit operation;
#u
Ctrl+r: Redo Previous undo operation
.: Repeats the previous edit operation
Turn screen operation:
Ctrl+f: one screen backward;
Ctrl+b: one screen ahead;
Ctrl+d: Back half screen
Ctrl+u: Forward half screen
Vim built-in tutorials:
Vimtutor
Vim's last-line mode:
(1) Address, delimitation
: Start_pos,end_pos
#: Line #;
#,#
#,+#
.: When moving forward
$: Last line
%: Full text, equivalent to 1,$
/PAT1/: The first time the line is matched to this pattern;
#,/pat1/
/pat1/,/pat2/
After you can follow the edit command:
D, y
W, R
(2) Find
/pattern: to the tail
? PATTERN: To the header
N: Same direction as command
N: Opposite direction of command
(3) Find and replace
S: In the last line mode, the search and replace operation is done within the bounds of the address;
s/what to look for/replace with content/modifiers
What to look for: Available modes
What to replace: You cannot use a pattern, but you can use a back reference symbol to refer to what the grouping brackets in the preceding pattern match to;
\1, \2, ...
&: Refers to the entire content of the "What to find" matches;
Modifier:
I: Ignore case
G: Global Substitution
/: Used for delimiters, so, to find the content or replace with the content that appears in this symbol, to use \ to escape it, use format: \/
The delimiter can be replaced with other characters: @, #等, for example;
Multi-file Mode:
Vim FILE1 FILE2 ...
: Next
: First
:p Rev
: Last
: Wqall
: Q!all
Multi-File Window segmentation:
Vim-o|-o FILE1 FILE2 ...
Ctrl+w, ARROW
Single File Window segmentation:
Ctrl+w, S:split, horizontal split
Ctrl+w, v:vertical, vertical split
Some of the working features of the custom vim:
(1) Line number
Display: Set Nu
Disabled: Set Nonu
(2) Bracket matching
Display: Set SM
Disabled: Set NOSM
(3) Auto indent:
Set AI
Set Noai
(4) Highlight Search
Set Hlsearch
Set Nohlsearch
(5) Syntax coloring
Syntax on
Syntax off
(6) Ignore character case
Set IC
Set Noic
: Help for assistance
: Help SUBJECT
The permanent effect of the feature setting is as follows:
Global configuration file:/ETC/VIMRC
User profile: ~/.VIMRC
Jobs: Copy the/etc/grub.cfg configuration file to the/tmp directory and use the Find and replace command to delete white space characters from the beginning of the/tmp/grub.cfg file
:%s/^[[:space:]]/g
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/B0/wKiom1XrpUOh_fsIAAI0qXUHtMc332.jpg "/>
Copy the/etc/rc.d/init.d/functions file to the/tmp directory and add a # to the beginning of the line with the Find Replace command for each line beginning with a blank character for/tmp/functions; Original whitespace character reserved
:%s/^[[:space:]]/#/g
Replace/etc/sysconfig/init in/tmp/functions file with/var/log
:%s#/etc/sysconfig#/var/log#g
Delete the line at the beginning of the/tmp/functions file so # begins with # followed by at least one blank character #
:%s/^[#+[:space:]]//q
A simple application of the VIM editor