Command actions
1. Three modes
Command mode, insert mode, last line mode
Mode conversion
Command mode –> insert mode A,a,i,i,o,o
Insert mode –> Command mode ESC
Command mode –> last-line mode:
Last-line mode –> Command mode ESC
2. Command operation
1) The default entry is the command mode
Vim filename
I insert before cursor
I Insert at the beginning of the cursor
A after the cursor is inserted
A cursor sits at the end of the line insert
o Cursor Downward insertion
O cursor Upstream insertion
2) Cursor Movement
H Left
J Down
K On
L Right
W to the top of the next word
E to the end of the next word
B to the beginning of the previous word
GE to the end of the previous word
The F letter searches backwards for letters and jumps to the first matching position
F Letter Forward Search letter, jump to first match position
0/^/home move to the beginning of the cursor
$/end move to the end of the line where the cursor is
G File First line
GG file Tail Line
NG file nth Row
N: Nth file n
3) Copy, cut, paste, delete, replace
YY the copy cursor is in the row
NYY copy cursor is the row following n rows
y^ copy cursor to the beginning of the line (without the character at the cursor)
y$ copy cursor to end of line (with character at cursor)
YG copy cursor to tail line
Y1G copy cursor to first line
P Paste Cursor Line downstream
P paste cursor on row upstream
DD deletes the cursor in the row
NDD Delete the line following n rows of the cursor
Using the Paste command at this point is equivalent to clipping
D Delete cursor to end of line
DW deletes the cursor to the end of the line, or deletes a single word
X Delete character at cursor
X before deleting the cursor
4) File Save
: W Save
: q! Exit does not save
: Wq Save Exit
: Wq/path/filename also saved to/path/filename
: N,m w/path/filename N to M Row, save as/path/filename
: n,m W >>/path/filename N to M Row, append to/path/filename
: R/path/filename read/path/filename to the Open file
5)
:! CMD Execute shell command
: E/path/filename Open/path/filename file
6) Search
/string Search from top down
? string search from bottom to top
/\cstring Case insensitive
/\<string find starts with string
/\sting\> find ends with string
/\<string\> Find string
/\<\d\d\d\> finding three-bit numbers
7) Replace
: s/old/new Replace cursor line once
: s/old/new/g replace cursor in the row
:%s/old/new/g Full Text replacement
:%S/OLD/NEW/GC full text replacement, need to confirm
10,20s/old/new/g 10-20 Line Replacement
:., $s/old/new/g current line to tail line substitution
:%s/^/string/g all headers and strings
:%s/$/string/g all line endings plus string
: g/^$/d Delete all empty rows
: v/^$/d Delete opposite line
:%s/string//g Delete String
:%s/^string//g Delete characters beginning with string
8)
. Indicates the last command executed
Vu converted to lowercase
VU converted to uppercase
g~~ Conversion case
GGGUG Global Conversion lowercase
GGGUG Global Conversion Capitalization
~ Convert case
VEU Select Word Capitalization
ve~ modifying word Capitalization
:%s/\<./\u&/g to capitalize the first letter of a word
:%s/\<./\l&/g Set the first letter of the word lowercase
:%s/.*/\u& Set letter caps per line
:%s/.*/\l& Set lowercase letters per letter of beginning
9)
: Set NU Displays line number
: Set ignorecase is case insensitive
: Set Shiftwidth=n sets n spaces as indent size
>>
<<
: Syntax on syntax highlighting open
: syntax off syntax highlighting off
This article is from the "Start from the Heart" blog, please be sure to keep this source http://hao360.blog.51cto.com/5820068/1718498
Vim operation using