vi filename
, and editZZ
, save file:w
, save:w new-filename
, saveAs:w!
, force write:e!
, resume:q!
, force quit:!rm junk-file
:!df
h
, j
, k
, l
1
, 2
, …0
, move tobeginning of line$
, move to end of line^
, move to first non empty charw,b
, move by word, forword, backword, respectively.W,B
, move by BIG word, forword, backword, respectively. “-” connected words are treated as one8G
, move to 8th lineG
, move to END of filegg
, like 1G
-
, +
a
, append; (not necessary, I will customize these key to other use)i
, insert;c
, change;
cw, cb
, change word, forward, backward, respectivelyc2w
, change 2 words, forwardc^
, to first not empty charc0, c$
, to begin, end of line, or you use c[Home], c[End]
d
, delete;
dw
, by worddb
, by word, backwarddd
, delete lined$, d[End], D
, delete to end of linedto
, dTx
, delete to(not include) “x”, forward / backwardd/th
, delete until first match of “th”(很有用)diw
, delete current worddi(
, delete within the current parenss
, substitude
s
(one and more char), S
(whole line).x, X
, delete one char, forward, or backward, respectively (not necessary)
xP, XP
, delete and paste backxp, Xp
, swap two charsy
, yank;p
, put;
$p
, paste to end of line0P
, ^P
, paste to begin of linecc, dd, yy
(command)(text object)
(command)(number)(text object)
(number)(command)(text object)
cc
, change whole lineC
, like c$
~
, change case.
u
, C-r
, U
, seems work differently in evil-mode4i<space><Esc>
cc
, dd
, yy
, apply to lineC
, D
, S
apply from current position to end, while Y
, the whole lineC
=== c$
, D
=== d$
, but Y
=== yy
, instead of y$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r
, dd
, P
, cw
, x
With a editor you can scrooll the page, With a screen editor you can scroll the page,
move the cursor, delete lines, nisret move the cursor, delete lines, insert
characters, and more wrile results of characters, and more while results of
your edits as you make tham. your edits as you make them.
Since they allow you to make changes Screen editors are very popular.
as you read through a file, much as Since they allow you to make changes
you would edit a printed copy, as you read through a file, much as
screen editors are very popular. you would edit a printed copy.
P
, p
, .
With a screen editor you can With a screen editor you can
scroll the page. scroll the page.
move the cursor. With a screen editor you can
delete lines. move the cursor.
With a screen editor you can
delete lines.
J
With a With a screen editor you can scroll the page, move the cursor
screen editor
you can
scroll the page, move the cursor
C-b
, C-f
,C-u
(not work in emacs evil-mode), C-d
,C-y
, C-e
z<Enter>
, z.
, z-
, move to top/center/bottom and scroll to it (not as good as emacs’ recenter-top-center
, i will drop this in my evil-mode)C-l
(not work in my evil-mode, we have recenter-top-center
)H
, M
, L
: to top/middle/bottom of screen2H
, 2L
: 2 second line from top/bottom+
, <Enter>
, -
, move to first char of next/previous line.20|
, move to column 20, ^
, move to first nonblank char.e
, E
, end of word, (ignore punctuations)(
, )
, beginning of current/next setence{
, }
, beginning of current/next paragraph[[
, ]]
, beginning of current/next section/pattern
, ?pattern
, search forward/backwardn
, next matchN
, next match, opposite position:set nowrapscan
, dont do loop searchd/pattern
fx
, Fx
, move on to previous/next ‘x’tx
, Tx
, move before char ‘x’, previous/next;
, ,
, repeat same direction, opposite direction7fx
, move to 7th matchdfx
, e.g. dfi
, delete from here to first occurance of ‘i’, then d;
, delete to second occurance of ‘i’20G
, move to Line #20``
, move back (old position)''
, move back, but at the beginning of line
With a screen editor you can scroll the
page, move1 move2 move4 move5 move6 move7 the cursor, dlete lines, insert
characters, and more, while seeing the
characters, ang the
results of your edits as you make them.
Change |
Delete |
Copy |
From cursor to… |
cH |
dH |
yH |
Top of screen |
cL |
dL |
yL |
Bottom of screen |
c+ |
d+ |
y+ |
Next line |
c5| |
d5| |
y5| |
Column 5 of current line |
2c) |
2d) |
2y) |
Second sentence following |
c{ |
d{ |
y{ |
Previous paragraph |
c/pattern |
d/pattern |
y/pattern |
Pattern |
cn |
dn |
yn |
Next pattern |
cG |
dG |
yG |
End of file |
c13G |
d13G |
y13G |
Line number 13 |
vi +3 filename
, open file at 3rd linevi + filename
, open file at last linevi +/pattern filename
, open file at first occurance of patternvi +R filename
, read file in read-only modevi -r filename
, ex -r filename
, Recovering a Bufferdyy
, yank to buffer “d”ayw
, yank to buffer “a”ap
, dp
, put buffer “a”/“d”mx
, mark current position to x'x
, `x
, move to mark x. (first char, or exact position)''
, ``
, move to last position __ _ _ _ _
/ _| ___ _ __ | | __ _| |_ ___ _ __ _ __ ___ __ _ __| (_)_ __ __ _
| |_ / _ \| '__| | |/ _` | __/ _ \ '__| | '__/ _ \/ _` |/ _` | | '_ \ / _` |
| _| (_) | | | | (_| | || __/ | | | | __/ (_| | (_| | | | | | (_| |
|_| \___/|_| |_|\__,_|\__\___|_| |_| \___|\__,_|\__,_|_|_| |_|\__, |
|___/
:s/old/new
, substitude first occurance of old:s/old/new/g
, many occurance:50,100s/old/new/g
, :50,100s/old/new
apply to 50~100 lines:1,$s/old/new
, apply to whole filey
for yesn
for noEnter
, quit:%s/old/new/g
, no confirm, whole file:g/pattern/s/old/new/g
,:1,200g/pattern/s/old/new/g
:g/pattern/s/old/new/g
, same as :g/pattern/s//new/g
.
, single char, except a newline*
, match zero or more occurance of previous char
a*
can match a
, aa
, aaa
, etc.*
can mathc any char(s) combination^, $
, when it is the first/last char of regex, treated as line beginning/ending, else treated as itself.
^Line
match any line starts with “Line”something^*
, can match “something”, “something“,”something^”, etc[]
, e.g. [aoei]
match a
, o
, e
, i
; and [a-z]
, ;:[a-z0-9]
works as expected.:%s/\(That\) or \(this\)/\2 or \1/
~
, match last seach history. Like you seached “the” with /the
, then you can search for “then” with /~n
\
, e.g. \.
match “.”\<m
, \>tion
, match words begin with ‘m’, end with “tion”[:alnum:]
Alphanumeric characters[:alpha:]
Alphabetic characters[:blank:]
Space and tab characters[:cntrl:]
Control characters[:digit:]
Numeric characters[:graph:]
Printable and visible (nonspace) characters[:lower:]
Lowercase characters[:print:]
Printable characters (includes whitespace)[:punct:]
Punctuation characters[:space:]
Whitespace characters[:upper:]
Uppercase characters[:xdigit:]
Hexadecimal digitss/old/NEW/g
\n
, n is 1..9, match (THIS)&
, mathed part~
, s/thier/their/
, then s/her/~/
is like s/her/their
\u, \l
, uppercase/lowercase char. :s/\(That\) or \(this\)/\u\2 or \l\1/
\U, \L, \e, \E
, uppercase region, or whole match:set ic
, ignore case:s//~/
, repeat last substitution:%&g
, Repeat the last substitution everywhere:%s;/user1/tim;/home/tim;g
/four
, <Enter>
, cwfive
, n
(repeat search), n
(bypass one match), .
(apply last cwfive
)Examples
<p>something</p> <p>somethingelse</p>
<a>something</a> ===> `:%300,400g/<p>/s/something/somethingelse/g` ===> <a>something</a>
<a>something</a> <a>something</a>
<p>something</p> <p>somethingelse</p>
one (one)
two (two)
three ===> `:348,352s/.*/(&)/` ===> (three)
four (four)
five (five)
That or this ===> `:%s/\(That\) or \(this\)/\2 or \1/` ===> this or That
__ _ _ _ _
/ _| ___ _ __ | | __ _| |_ ___ _ __ _ __ ___ __ _ __| (_)_ __ __ _
| |_ / _ \| '__| | |/ _` | __/ _ \ '__| | '__/ _ \/ _` |/ _` | | '_ \ / _` |
| _| (_) | | | | (_| | || __/ | | | | __/ (_| | (_| | | | | | (_| |
|_| \___/|_| |_|\__,_|\__\___|_| |_| \___|\__,_|\__,_|_|_| |_|\__, |
|___/
:set
Command
:set option
, or :set nooption
.exrc
File:!cmd
:r !date
, output to file, Thu May 1 12:59:55 CST 2014:. !date
, same as :r
, but overwrite current line:r Learning-Vim.md
, this is …. Good.:%!sort
, you try you die…!)cmd
, pass these sentence to cmd!!
, current line!2!
, 2!!
, two lines:ab abbr phrase
:unab abbr
这些是我从 StackOverflow 上看到的。
diw
, di"
, di{}
:!xxd
, hex editor :!xxd -r
de
, then .
as you wantddp
, swap current and next linebye
, yiw
'.
, last edited line`.
, last edited char:changes
, list changes:g/rgba/y A
10.gv
, reselects last visual selectiong~~
, gUU
, guu
>>
, <<
, indent#
, *
, search word under cursorRefs
Read more