Vim is a powerful text editor that provides several key features:
1. It allows editing multiple files at the same time in different windows.
2. Vim uses modes to perform different actions, which are introduced using consistent notation.
3. Vim is highly customizable and extensible through scripts.
2. 2
, Vim
, Vim ,
, Vim ,
, , ,
. .
Vim ,
.
, , .
, , , Vim
,
, .
. ,
,
. Vim .
, Vim ,
. , ,
, .
Vim .
notepad, word, edit , ,
. Vim ,
. BUG
. ,
Vim( vi)
,
,
, Vim .
Vim .
,
, .
Vim . notepad, edit
.
, ,
, ? , UNIX ,
, :help xxx .
. ,
. . ,
, , , ,
, .
2
3. 3
.
, , ,
Mission Impossible .
. Vim ,
. .
i18n internationalization, Vim
the teh , Vim
, script,
. Vim .
Vim . Vim
SHELL . Vim
.
Vim .
, , , Vim
, Vim ,
, , ,
, ; LTEX
A , LTEX
A
. , ,
, ,
email slimzhao@hotmail.com
, .
The Vim user manual and reference manual are
Copyright (c) 1988-2002 by Bram Moolenaar. This
material may be distributed only subject to
the terms and conditions set forth in the Open
Publication License, v1.0 or later. The latest
version is presently available at:
http://www.opencontent.org/openpub/
People who contribute to the manuals must agree
with the above copyright notice.
Vim .
slimzhao@hotmail.com
2004/06/08
3
5. 5 6.3.0
6.3.0
1. 6.3.0 ?
VIM 6.3, 6.1
. . ,
?
2. 6.3.0 0.2 :
(A) 0.1 0.2 usr 21.txt, usr 22.txt, usr 29.txt, usr 45.txt 4
, 4 ,
.
(B) , shell , ,
, :
ex command
:au BufRead *.tip setf tip
.
7 . , Vim
, ex command, 6 :
normal mode command
Vim normal , .
normal mode command
gg=G
shell command
unix shell , windows OS DOS
BOX . :
shell command
env LANG=de_DE.ISO_8859-1 vim
Display
,
. :
5
6. 6 6.3.0
Display
:!make | &tee /tmp/vim215953.err
gcc -g -Wall -o prog main.c sub.c
main.c: In function 'main':
main.c:6: too many arguments to function 'do_sub'
main.c: At top level:
main.c:10: parse error before '}'
make: *** [prog] Error 1
2 returned
"main.c" 11L, 111C
(3 of 6): too many arguments to function 'do_sub'
Hit ENTER or type command to continue
List
, :
List
r Insert
o Normal "o" "O"
c 'textwidth'
code, :
code
while i < b {
if a {
b = c;
}
}
url, :
URL
http://www.cl.cam.ac.uk/~mgk25/download/ucs-fonts.tar.gz
(C) cmtt, computer modern
typewriter, , cmr(computer modern roman) .
, Latex A L TEX
cmr, cmtt : LE .
A X
T A
.
(D) , ,
, ,
.
URL . email
mail .
6
7. 7 6.3.0
(E) ‘‘...’’(LTEX
A ), ... ,
"...", , ’ ,
', ,
. /hello hi,
hi .
(F) , CTRL-N,
<Esc>
(G) BUG, .
, , ,
...
(H) , PDF HTML, HTML bgcolor
. , PDF
. PDF Tex .
. .
. .
, PL (Public License,
Piao Liang). windows
. .
3. TODO:
, . ,
upquote LTEX package,
A ’ ' .
,
. fancyvrb ,
--- .
, . LT
A
EX , TMD
, , .
.
7
9. 9 00
|usr 29.txt|
|usr 30.txt|
|usr 31.txt| GUI
Vim
|usr 40.txt|
|usr 41.txt| Vim
|usr 42.txt|
|usr 43.txt|
|usr 44.txt|
|usr 45.txt|
Vim
|usr 90.txt| Vim
HTML PDF
:
http://vimdoc.sf.net
, Vim .
|usr 01.txt|
|01.1|
|01.2|
|01.3| Vim
|01.4|
|usr 02.txt| Vim
|02.1| Vim
|02.2|
9
21. 21 01
shell command
vim -u NONE -c 'e $VIMRUNTIME/tutor/tutor.fr' -c 'w! TUTORCOPY' -c 'q'
vim -u NONE -c "set nocp" TUTORCOPY
Vim happy .
3. del TUTORCOPY
*01.4* *manual-copyright*
Vim : c 1988-2003 by Bram
Moolenaar. " "1.0
, :
http://www.opencontent.org/opl.shtml
.
*frombook*
Steve Oualline Vi IMproved - Vim
( New Riders , ISBN:0735710015). " "
, ( ,
, Vim 6.0 ).
|frombook| .
Steve Oualline New Riders OPL
! . ,
.
,
. |iccf|.
: |usr 02.txt|
: |manual-copyright| vim:tw=78:ts=8:ft=help:norl:
21
22. 22 02 Vim
*usr 02.txt* Vim 6.3 . : 2003 05 04
VIM --- : Bram Moolenaar
Vim
Vim .
. .
, .
|02.1| Vim
|02.2|
|02.3|
|02.4|
|02.5|
|02.6|
|02.7|
|02.8|
: |usr 03.txt|
: |usr 01.txt|
: |usr toc.txt|
*02.1* Vim
:
shell command
gvim file.txt
Vim.
UNIX , Microsoft
Windows, MS-DOS .
Vim file.txt .
, . :
22
23. 23 02 Vim
Display
+---------------------------------------+
|# |
|~ |
|~ |
|~ |
|~ |
|"file.txt" [New file] |
+---------------------------------------+
("#" .)
(~) . , Vim
. ,
file.txt, . ,
.
VIM
gvim . :
shell command
vim file.txt
. , xterm
, xterm . Microsoft
Windows MS-DOS , .
, gvim
, .
*02.2*
Vim .
. Normal . Normal
. Insert
.
Vim Normal . Insert "i"
(i Insert). . ,
. :
Display
iA very intelligent turtle
Found programming UNIX a hurdle
23
24. 24 02 Vim
"turtle" . <Esc> Insert
Normal . Vim :
Display
+---------------------------------------+
|A very intelligent turtle |
|Found programming UNIX a hurdle |
|~ |
|~ |
| |
+---------------------------------------+
?
, :
ex command
:set showmode
.
( , ).
(
).
, "i" Vim --INSERT--.
Insert .
Display
+---------------------------------------+
|A very intelligent turtle |
|Found programming UNIX a hurdle |
|~ |
|~ |
|-- INSERT -- |
+---------------------------------------+
<Esc> Normal "--INSERT--"
1
Vim --- ,
.
, <Esc> Normal ( Normal
1
: Normal --NORMAL--,
24
25. 25 02 Vim
). <Esc>, Vim ,
1
Normal
*02.3*
Normal , :
List
h
j
k
l
. l right ?
, :
, .
( )
: .
.
.
? ,
, ;
hjkl .
: h , l
, j .
k
h l
j
, .
"i" Insert , hjkl
, <Esc> Normal .
|vimtutor| .
, Hiroshi Iwatani :
1
: google ,
25
26. 26 02 Vim
Display
Komsomolsk
^
|
Huan Ho <--- ---> Los Angeles
(Yellow river) |
v
Java (the island, not the programming language)
*02.4*
, "x". (
, xxxx )
, xxxxxxx(7 x) "A very ".
:
Display
+---------------------------------------+
|intelligent turtle |
|Found programming UNIX a hurdle |
|~ |
|~ |
| |
+---------------------------------------+
, :
Display
iA young <Esc>
i( Insert ), "A young", Insert
( <Esc>). :
Display
+---------------------------------------+
|A young intelligent turtle |
|Found programming UNIX a hurdle |
|~ |
|~ |
| |
+---------------------------------------+
"dd" . :
26
27. 27 02 Vim
Display
+---------------------------------------+
|Found programming UNIX a hurdle |
|~ |
|~ |
|~ |
| |
+---------------------------------------+
Vim ,
: "J". :
Display
A young intelligent
turtle
"J":
Display
A young intelligent turtle
. , "u"
1
, .. , "dd"
, "u" . :
A :
Display
A young intelligent turtle
xxxxxxx "A young". :
Display
intelligent turtle
"u" . g,
:
Display
g intelligent turtle
1
: , , ...
27
28. 28 02 Vim
u :
Display
ng intelligent turtle
u, :
Display
ung intelligent turtle
oung intelligent turtle
young intelligent turtle
young intelligent turtle
A young intelligent turtle
: "u"
, Vim Vi .
|not-compatible| .
Vim Vim . Vi
, .
, CTRL-R( ) .
, . CTRL-R , A
:
Display
young intelligent turtle
, "U" , .
"U" .
Display
A very intelligent turtle
xxxx very
A intelligent turtle
xxxxxx turtle
A intelligent
"U"
A very intelligent turtle
"u" "U"
A intelligent
28
29. 29 02 Vim
"U" , "u" CTRL-R
. , , "u" CTRL-R
.
*02.6*
Vim . |Q in| ,
.
"i" .
? . "a"
"i".
,
Display
and that's not saying much for the turtle.
Display
and that's not saying much for the turtle!!!
, "x" .
turtle e . :
normal mode command
a!!!<Esc>
e :
Display
and that's not saying much for the turtle!!!
"o" , Insert
. .
:
Display
A very intelligent turtle
Found programming UNIX a hurdle
29
30. 30 02 Vim
"o" :
normal mode command
oThat liked using Vim<Esc>
:
Display
A very intelligent turtle
That liked using Vim
Found programming UNIX a hurdle
"O" ( O) .
9 . "kkkkkkkkk" "9k" .
, .
, , "a!!!<Esc>".
"3a!<Esc>" . 3 3 .
, 3 "3x".
.
*02.7*
Vim, "ZZ". Vim.
: Vim ,
. "ZZ", Vim
. .
Vim . |07.4|.
. . Vim :
ex command
:q!
.
30
31. 31 02 Vim
, 3 :
(:), ; q , ;
1 2
(.!) .
, Vim
. ":q" , Vim
:
Display
E37: No write since last change (use ! to override)
Vim, " ,
".
, ":e!" .
*02.8*
Vim , !
ex command
:help
. <F1>
<F1>.
, ":help"
. Vim ( )
: .
. hljk .
, "ZZ" .
, Vim.
, (
|help|). .
CTRL-]( ),
. ( , Vim
. CTRL-] word
3
.
1
: Vim
2
: :! , , w!
3
: , HTML , HTML
31
32. 32 02 Vim
, , CTRL-T( )
. CTRL-O( ) .
*help.txt* . "*"
( ).
|29.1| .
, :
ex command
:help {subject}
"x" , :
ex command
:help x
, :
ex command
:help deleting
Vim , :
ex command
:help index
( , CTRL-A),
"CTRL-" :
ex command
:help CTRL-A
1
Vim . Normal
. , Normal CTRL-H :
ex command
:help CTRL-H
, . Insert
, "i " . CTRL-H :
<a href="http://www.w3.org/2001/HTML">HTML</a>
Vim tag ,
Vim
1
: Insert Normal
32
33. 33 02 Vim
ex command
:help i_CTRL-H
Vim , . - .
-t , :
ex command
:help -t
Vim .
, . 'number' ,
:
ex command
:help 'number'
|help-context| .
. Insert
, :
ex command
:help i_<Up>
:
Display
E37: No write since last change (use ! to override)
ID :
ex command
:help E37
: |usr 03.txt|
: |manual-copyright| vim:tw=78:ts=8:ft=help:norl:
33
34. 34 03
*usr 03.txt* Vim 6.3 . : 2004 01 17
VIM --- : Bram Moolenaar
, ,
Vim . .
, |Q lr| .
|03.1| Word
|03.2|
|03.3|
|03.4|
|03.5|
|03.6|
|03.7|
|03.8|
|03.9|
|03.10|
: |usr 04.txt|
: |usr 02.txt|
: |usr toc.txt|
*03.1* Word
"w" word. Vim
, "w" word.
"3w" 3 words. :
Display
This is a line with example text
--->-->->----------------->
w w w 3w
word "w"
word . "b"1 word
:
1
: : backward
34
35. 35 03
Display
This is a line with example text
<----<--<-<---------<---
b b b 2b b
, "e"1 word 2
. "w"
"b" , "e" "ge",
3
word :
Display
This is a line with example text
<- <--- -----> ---->
ge ge e e
word, "w"
word . "w" , "l"
. "b" , .
non-word , ".", "-" ")" word
. Vim word , 'iskeyword' .
WORDs . WORD word
. WORD word.
, :
Display
ge b w e
<- <- ---> --->
This is-a line, with special/separated/words (and some more).
<----- <----- --------------------> ----->
gE B W E
, .
*03.2*
"$" . <End> ,
.
4
"^" . "0"
1
: :end of word
2
: "w" , word ,
"e" word
3
: , "e" , word ,
word
4
:
35
36. 36 03
. <Home> .
:
Display
^
<------------
.....This is a line with example text
<----------------- --------------->
0 $
("....." )
"$" , .
.
. "1$" , "2$"
, .
"0" , "0" ,
"0" , ,
1
, "^" .
*03.3*
. "fx"
x. : "f" "find".
, , human h
. "fh" :
Display
To err is human. To really foul up you need a computer.
---------->--------------->
fh fy
"fy" really .
; "3fl" "foul" "l" :
Display
To err is human. To really foul up you need a computer.
--------------------->
3fl
2
"F" :
1
: "^" ,
2
: : ,
36
37. 37 03
Display
To err is human. To really foul up you need a computer.
<---------------------
Fh
"tx" "fx" , ,
. : "t" "To".
"Tx":
Display
To err is human. To really foul up you need a computer.
<------------ ------------->
Th tn
4 ";" . "," ,
1
. , 4
2
.
*03.4*
() . %3
:
. "(" , ")" ,
4
")" , "(" :
Display
%
<----->
if (a == (b * c) / d)
<---------------->
%
[] {} . ( 'matchpairs'
5
)
, "%"
. , "%"
"(", ")":
1
: "Fx" , "," ,
2
: , "fx" x , "f" ,
, , , Vim
, Windows ,
3
, (qzhen@flotu.org)
4
:
5
, <>, HTML, XML
37
38. 38 03
code
if (a == (b * c) / d)
---+---------------->
%
*03.5*
C C++ ,
:
Display
prog.c:33: j undeclared (first use in this function)
33 . 33
? "9999k"1 "32j" 32 .
2
, . "G" .
, .
"33G" 33 . (|usr 30.txt|
, :make )
3
, "G" .
"gg" . "1G" ,
.
Display
| first line of a file ^
| text text text text |
| text text text text | gg
7G | text text text text |
| text text text text
| text text text text
V text text text text |
text text text text | G
text text text text |
last line of a file V
1
: 9999 , C/C++ ,
,
, Vim .
2
: : G Go
3
: , Vim
,
,
38
39. 39 03
1
"%" .
2 3
"50%" . "90%" .
,
.
? :
Display
+---------------------------+
H --> | text sample text |
| sample text |
| text sample text |
| sample text |
M --> | text sample text |
| sample text |
| text sample text |
| sample text |
L --> | text sample text |
+---------------------------+
: "H" Home, "M" Middle, "L" Last.
*03.6*
, :
1. CTRL-G . ( 'ruler'
):
Display
"usr_03.txt" line 233 of 650 --35%-- col 45-52
, ,
, .
- , "col 2-9".
, , 8
, 9.
4
2. 'number' . :
ex command
:set number
1
: N
2
: , 50%
3
: Vim , ,
? :goto 3
4
:
39
41. 41 03
Display
+----------------+
| some text |
| some text |
| some text |
+---------------+ | some text |
| some text | CTRL-U --> | |
| | | 123456 |
| 123456 | +----------------+
| 7890 |
| | +----------------+
| example | CTRL-D --> | 7890 |
+---------------+ | |
| example |
| example |
| example |
| example |
+----------------+
CTRL-E( ) CTRL-Y( ). :
CTRL-E Extra. ( MS-Windows , CTRL-Y
).
( ) CTRL-F. CTRL-B
1 2
. CTRL-F , CTRL-B , !
"j"
. . "zz"
:
Display
+------------------+ +------------------+
| some text | | some text |
| some text | | some text |
| some text | | some text |
| some text | zz --> | line with cursor |
| some text | | some text |
| some text | | some text |
| line with cursor | | some text |
+------------------+ +------------------+
3 4
"zt" , "zb" .
1
: : Forward
2
: : Backward
3
: "zt" t top, z ,
, zt Zhuan Tie( ) :-)
4
: : "b" bottom
41
42. 42 03
, |Q sc|.
, 'scrolloff' .
*03.8*
"/string" . "include",
:
normal mode command
/include
1
"/" Vim ,
, .
.
.
: .*[]^%/?~$ ,
, .
.
. "n" .
#include:
normal mode command
/#include
"n". #include .
, "n"
. "3n" 3 . "/"
2
.
3
"?" "/" , :
1
: Vim ,
2
: , normal ,
/ , N , N ,
/ , /text ,
n N , / N , :
a 1 b
a 2 b
a 3 b
a 4 b
a 5 b
a 6 b
normal 1 , 2/d 3, 2
, n , 4
3
: : Vim
42
43. 43 03
normal mode command
?word
"N" , "/" "?" .
"/" "N" , "?" "N"
.
.
, 'ignorecase' :
ex command
:set ignorecase
"word", "Word" "WORD".
, :
ex command
:set noignorecase
3 :
normal mode command
/one
/two
/three
"/" , . ,
Vim "/three" , "three".
, , Vim "/two".
"/one".
.
,
. "/o<Up>"1 Vim "/one"
.
":" .
. .
1
: <Up>
43
44. 44 03
WORD
word "TheLongFunctionName",
. "/TheLongFunctionName",
. Vim .
: word , "*" .
1
Vim word .
"#" "*" . :"3*"
word .
WORD
"/the" Vim "there".
"the" :
normal mode command
/the>
"" , word . , ""
2
word . word "the" :
normal mode command
/<the>
"there" "soothe". "*" "#"
word word( "g*" "g#"
word .)
"nr" .
. "nr"
"*" "n" .
. :
ex command
:set hlsearch
1
: : word ? ?
: Visual select, yank, :let @/=@", n
2
: word , ,
, 0
44
45. 45 03
"nr", Vim .
, ,
1
:
ex command
:set nohlsearch
.
2
, :
ex command
:nohlsearch
'hlsearch' . .
, .
"n" "N" .
. :
ex command
:set incsearch
Vim .
.
:
ex command
:set nowrapscan
. ,
. 'wrapscan' ,
.
INTERMEZZO
3
, Vim
, Vim .
|not-compatible| .
:
1
A: ? : |/%<3l|
2
:
, , 'hlsearch'
3
:
45
46. 46 03
ex command
:scriptnames
, :
ex command
:edit ~/.vimrc
, Vim
. :
ex command
Go:set hlsearch<Esc>
"G" . "o" ,
":set" . <Esc> . :
normal mode command
ZZ
Vim , 'hlsearch' .
*03.9*
Vim .
, . ,
, .
.
|usr 27.txt|. |pattern| .
^ .
1
6 . "include"
include . "^include" include.
$ . "was$" was.
"x" "the" :
Display
the solder holding one of the chips melted and the
xxx xxx xxx
1
:
46
47. 47 03
"/the$" :
Display
the solder holding one of the chips melted and the
xxx
"^the" :
Display
the solder holding one of the chips melted and the
xxx
"/^the$" , "the"
. , "the ",
.
. . "c.m"
1
c m , . :
Display
We use a computer that became the cummin winter.
xxx xxx xxx
. , .
: . "ter."
, :
Display
We use a computer that became the cummin winter.
xxxx xxxx
"ter." 2 .
*03.10*
"G" , Vim
. Vim .
:
1
: , l , .
, , , , .
47
48. 48 03
normal mode command
``
1
, ,
. `
, `.
,
, . "/" "n" (
). "fx" "tx", word
"w" "e" .
, "j" "k" ,
.
`` . CTRL-O
( : O older). CTRL-I
( : I O ).
3 :
normal mode command
33G
/^The
CTRL-O
33 2 , "The" . CTRL-O
33 . CTRL-O "33G"
. CTRL-I 33 . CTRL-I
"/^The" :
Display
| example text ^ |
33G | example text | CTRL-O | CTRL-I
| example text | |
V line 33 text ^ V
| example text | |
/^The | example text | CTRL-O | CTRL-I
V There you are | V
example text
: CTRL-I <Tab> .
1
: , ' , : , ` 1
2
: , " " ,
48
49. 49 03
":jumps" .
">" .
Vim . "ma"
"a". a z 26 .
. Vim .
, `{mark}, {mark}
. :
normal mode command
`a
'mark( , ) mark
. `mark , `mark mark
.
.
,
.
s(start) :
normal mode command
ms
e(end) :
normal mode command
me
, :
normal mode command
's
'' , 'e
e .
1 2
s , e
, .
:
1
: start
2
: end
49
50. 50 03
ex command
:marks
. :
List
'
"
[
]
: |usr 04.txt|
: |manual-copyright| vim:tw=78:ts=8:ft=help:norl:
50
51. 51 04
*usr 04.txt* Vim 6.3 . : 2004 01 17
VIM --- : Bram Moolenaar
---
. 3
: , Visual .
|04.1|
|04.2|
|04.3|
|04.4| Visual
|04.5|
|04.6|
|04.7|
|04.8|
|04.9|
|04.10|
: |usr 05.txt| Vim
: |usr 03.txt|
: |usr toc.txt|
*04.1*
2 "x" .
"4x" 4 .
"dw" word. "w"
word . , "d" ,
.
, "4w" 4 word. "d4w" 4 word.
51
52. 52 04
Display
To err is human. To really foul up you need a computer.
------------------>
d4w
To err is human. you need a computer.
Vim . Vim
word . "e" word
1
, Vim :
Display
To err is human. you need a computer.
-------->
d2e
To err is human. a computer.
. " ",
" ".
"$" . "d$"
. " " , :
Display
To err is human. a computer.
------------>
d$
To err is human
: + .
. "d" .
"4l" "w". ,
.
*04.2*
"c", . "d" ,
Insert . "cw" word. ,
, word Insert :
1
: ,
52
53. 53 04
Display
To err is human
------->
c2wbe<Esc>
To be human
"c2wbe<Esc>" :
List
c
2w word( Insert )
be
<Esc> Normal
: "human"
. : ,
, . "cw" .
"c" d , :"cw", "ce" ,
word . word .
Vi . , Vim
1
.
"dd" , "cc" .
( ).
"d$" , "c$"
. "d$" "a" Insert .
+
:
List
x dl( )
X dh( )
D d$( )
C c$( )
s cl( )
S cc( )
1
: :
53
54. 54 04
"3dw" "d3w" 3 word. ,
"3dw" word 3 ;
"d3w" 3 word. .
, , "3d2w" word, 3 ,
6 word.
"r" .
. "cl" "s" , "r"
<Esc> Normal .
Display
there is somerhing grong here
rT rt rw
There is something wrong here
"r"
.
Display
There is something wrong here
5rx
There is something xxxxx here
"r<Enter>".
. :
1
"4r<Enter>" 4 .
*04.3*
"." Vim .
. , HTML , <B> .
<B> < "df>". </B> < "."
. "." ( "df>").
, < "." .
1
: : ,
54
56. 56 04
*04.4* Visual
+ .
.
Visual .
"v" Visual . .
. .
, :
Display
This is an examination sample of visual mode
---------->
velllld
This is an example of visual mode
"l"
. "d" .
, <Esc>
Visual . .
, "V" Visual .
. .
.
, "Vjj" 3 :
Display
+------------------------+
| text more text |
>> | more text more text | |
selected lines >> | text text text | | Vjj
>> | text more | V
| more text more |
+------------------------+
, CTRL-V
Visual . .
56