. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Vim . . . . . . . . . . . . . . . . . . . .
Vim(elvis). . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
1.3.1 Vim . . . . . . . . . . . . . . . . . . . . . . . .
1.3.2 elvis. . . . . . . . . . . . . . . . . . . . . . . .
1.3.3 nvi-m17n . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
1.4
1.4.1 Normal mode . . . . . . . . . . . . .
1.4.2 Insert mode. . . . . . . . . . . . . .
1.4.3 Cmdline mode or Command-line mode
1.4.4 Visual mode . . . . . . . . . . . . .
1.4.5 Select mode . . . . . . . . . . . . .
1.4.6 Ex Ex mode. . . . . . . . . . . . . . . .
1.5
step by step . . . . . . . . . . . . . . . . .
1.5.1 . . . . . . . . . . . . . . . . . .
1.5.2 vim . . . . . . . . . . . . . . . .
1.5.3 . . . . . . . . . . . . . . . . . . . . .
1.5.4 . . . . . . . . . . . . . . . . . . . .
1.1
1.2
1.3
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
2
3
3
3
4
4
4
4
4
5
5
5
5
5
6
6
6
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1
2.2
2.3
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1
additional mode . . . . . .
3.1.1 operator-pending mode
3.1.2 replace mode . . . . . . .
3.1.3 insert normal mode . .
3.1.4 insert visual mode . .
3.1.5 insert select mode. . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
11
11
11
12
12
12
3.2
3.3
3.4
3.5
3.6
. . . . . .
. . . . .
. . . . .
. . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . .
Register . . . . . . . . . . . . . . . . . .
4.2.1 register . . . . . . . . . . . . . . . .
4.3
. . . . . . . . . . . . . . . . . . . .
4.4
. . . . . . . . . . . . . . . . . . . . .
4.4.1 mouse . . . . . .
4.4.2 copy
. . . . . . . . . . . . . .
Vim .
substitute . . . . . . .
. . . . . . . . . . . .
Vim . . . .
5.5.1 . . . . . . .
5.5.2 . . . . . . .
5.5.3 . . . . . . .
5.5.4 :marks. . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
Vim . . . . . . . . . . . .
6.4.1 vim -x [] . . . . . . . . . . .
6.4.2 vim :X
. . . . . . . . . . . . . . . .
6.5
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
12
13
13
14
15
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
17
18
19
19
19
19
19
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
20
20
21
21
22
22
22
22
22
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
23
23
25
25
25
25
26
. . . . . . . . . . . . . . . . . . . . . . . . . . . 27
7.1
7.2
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.1
6.2
6.3
6.4
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.1
5.2
5.3
5.4
5.5
.
.
.
.
.
yank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.1
4.2
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
8.1
8.2
shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
ii
set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
9.1
9.2
9.3
9.4
9.5
9.6
9.7
. . .
9.1.1 Vim . . .
9.1.2 elvis . . .
9.1.3 nvi-m17n .
. .
set . . . .
softtabstop[sts] . . .
Vim modeline . . . .
. . . . . . . .
. . . . . . .
9.7.1 .vimrc . . . .
9.7.2 .gvimrc . . . .
9.7.3 .vim . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
31
31
32
32
32
33
37
38
39
39
39
41
42
10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
10.1
10.2
10.3
10.4
10.5
. . . . . . . . . . . . . . . . . .
metacharacter, or character classes .
. . . . . . . . . . . . . . . . .
& . . . . . . . . . . . . . . . . . .
greedy . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
43
47
48
48
49
11 Vim folding . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
. . . . . . . . . .
11.1.1 . . . . . .
11.1.2 . . . . . .
11.1.3 . . . . . .
11.2 . . . . . . . . . .
11.2.1 . . . . .
11.2.2 .
11.2.3 . . . . .
11.2.4 . .
11.2.5 .
11.1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
51
51
52
52
52
53
53
53
53
53
12 Vim tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
12.1
12.2
12.3
12.4
12.5
tag . .
tags . . . . . . .
tag . . . . . . .
tag . . . . . . .
Vim . .
12.5.1 doctags . . . . . . . .
12.5.2 Vim
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
iii
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
55
56
56
56
57
57
57
13 Vim script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
macro.
13.1.1 . .
13.1.2 . .
13.1.3 .
13.1.4
13.2 Vim script .
13.1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
59
59
61
62
63
63
14 Vim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
64
64
64
65
65
65
15 Vim tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
iv
vi
FAQ
vi emacs/xemcas
1.1 Vim
elvis, vile, nvi (nvim17n Big5 Vim1 )
Vim elvis2 vile emacs
nvi vi OReilly
Vim elvis
3
Vim Free Software4 CharityWare5
Vi IMproved
HTML()binarymanpage TEX/LATEX (
)
3 Vim Vim
4 http://www.gnu.org/philosophy/free-sw.html
5 http://iccf-holland.org
1 VIM
2 elvis
1.2. VIM(ELVIS)
: AIDS
ICCF
http://iccf-holland.org/click.html Amazon ICCF
( xemacs )
1.2 Vim(elvis)
http://www.vim.org/
http://vim.sf.net/download.php
ftp://ftp.vim.org/pub/vim/
http://elvis.the-little-red-haired-girl.org/
elvis
ftp://ftp.cs.berkeley.edu/ucb/4bsd/
ftp://ftp.foretune.co.jp/pub/tools/nvi-m17n/
nvi-m17n
Vim 6.1elvis 2.2h-betanvi 1.79
Vim
1.3.
1.3
1.3.1 Vim
1. configure
--enable-multibyte
--enable-xim
--enable-fontset
--enable-gui=gtk
--enable-perlinterp
perl
--enable-pythoninterp python
GUI gtk+
2. /.vimrc
set enc=big5
set guifontset=
guifontset guifont
guifontconsole xterm
guifontset
(1024x768)
set guifontset=-b&h-*-medium-r-normal-*-*-120-*-*-m-*-*-*,
\-arphic-*mingti2l*-medium-r-normal-*-*-190-*-*-c-*-big5-0
Windows guifontset guifont
set guifont=Andale_Mono:H11:W6
3. locale zh_TW.Big5 i18n
unset LC_ALL
export LC_CTYPE=zh_TW.Big5
1.3.2 elvis
elvis GUI XA+CV
1.4.
1.3.3 nvi-m17n
nvi *BSD m17n(multilingualization, m n 17
m17n)
nvi-m17n /.nexrc
set
set
set
set
set
noskipdisplay
displayencoding=big5
inputencoding=big5
fileencoding=big5
autodetect=tw
1.4
Vim basic mode
Esc
/ ?
1.4.6 Ex Ex mode
ex
gQ Ex visual
edline ed man ed ed
ex ed
1.5.2 vim
vim :e test.txt test.txt 1.5.1
1.5.2 test.txt test.txt
1.5.3
vim i vim
Backspace Del
vi
Esc vim elvis
1.5.4
Esc :w
vim :q:wq
:-)
e edit()w write()q quit(
)
distributions vim
vim/gvim vi
vi vim Slackware Linux vi elvis
vim/gvim vi *BSD
nvi
vi vi : ver
Enter vi vim +/
6
+
Vim
vi/vim
2.1
h
Backspace
Enter + Shift
Shift
Space
Ctrl+f
PageDown Forward
Crtl+b
PageUp Backward)
hjkl
vi hjkl
hjkl
Backspace Space hl
Vim elvis
jk Enter+
8
2.2.
Vim
2.2
0
0 o Hmoe
Shift
End Shift
gg
regular expression $
gg Vim elvis vi 1G 1
lG goto
w
word
PageDownPageUp
n|
n () Shift n
:n
n nG
2.3.
2.3
)
sentence
sentencesentence . ! ?
paragraph
paragraphparagraph
{}[]() { % }
Vim
10
Vim
11
3.2.
-- (insert) --
3.2
i
(insert)
(append)
(open)
0i gI(Vim )
(Joint)
split Enter macro
J EOL(End Of Line)
gJ J Vim elvis
Vim script
12
3.3.
3.3
Vim elvis Del
Backspace Vim
elvis
xx
dd
(delete line)
dw
(delete word)
dG
d1G
dgg( Vim)
d$
d0
d $
d$ d vi(m)
3.4
r
cc
cw
(word)(change)
Shift
c$
c0
R R s
s
undo vi undoVim elvis
Vim
U
Crtl+r
redo
Vim r
:-) Vim
elvis Vim big5/cp950
13
3.5.
r replace
3.5
Vim Vim
edsed
5dd
3r
3r
locale
5J
3x
5i A
Ecs A
2i sys Esc
syssys
5G
:5
5l
j
2 8
Vim
:-)
14
3.6.
3.6
>>
shiftwidth 8
<<
shiftwidth 8 :set
shiftwidth? :set shiftwidth=4
4 shiftwidth sw Shift
:ce(nter)
:ri(ght)
:le(ft)
textwidth(tw)
tw 80 80
sw
gqap
gqip
gqq
gqQ
textwidth Enter
keyin
EOLgq Vim
visual mode gq
gq d y
gq3q
gq2ap
gq5j
( j 5j
)
gq}
well
gq)
2 2.3
15
3.6.
Vim script
http://info.sayya.org/edt1023/vim/format.vim
$VIMRUNTIME/plugin
vim J gqap Vim
office
TEX/LATEX/texinfo/troff/groff
16
4
yank
yank
Vim copy
Vim yank put
y Vim
Vim
Vim
4.1
yy
2yy
y2y :-)
y0
y$
yw
word
y2w
yG
y1G
P p P
ayy
a 26
17
4.2. REGISTER
4 yank
append Enter
ditto marks shift
ap
5Ayy
a a
a a 26
Vim
:reg registers
0,1,2,. . . 9 p
% #
elvis Vim
4.2 Register
Vim buffers
6.2 23yank Put registers
marks 5.4 21
RAM
18
4.3.
4 yank
4.2.1 register
4.3
.
yy p
. dddwrcw
4.4
4.4.1 mouse
console X terminal windows
Shift+Insert Ctrl+v Vim windows
4.4.2 copy
:set paste Vim elvis elvis :set noai1
GUI
1 set
19
Vim
Vim regular
expression, regexp pattern
pattern pattern
regexp
regexp
5.1
/
c-mode / /
Enter ? / / ?
5.2 Vim
*
word
* #
g* *
g# # n, N
20
5.3. SUBSTITUTE
5.3 substitute
:[range]s/pattern/string/[c,e,g,i]1
range
1,7 1,$
% %
#
pattern regexp
string
pattern string
confirm
error
globe
ignore
g cgi
[] :%s/Edwin/Edward/g
Edwin Edward
regexp
:-)
5.4
Vim marks
mark
mx x 26 mark
x
mark G a
1 :opt[ion] :opt
:option
21
5.5. VIM
5.5 Vim
5.5.1
5.5.2
mA viminfo vim
vim A (vim A
):-)
5.5.3
0
1 m
vim viminfo :h
viminfo-file-marksviminfo vim
mark ()() Ctrl + O
5.5.4 :marks
22
Vim
Vim
6.1
vim +
:-)
vim +n
vim +/string
/
string n string string
regexp
6.2
vim
argument list vim buffer list
buffer
23
6.2.
:n
:2n
:N
argument list
:e
vim vim
Tab
:e# Ctrl+
:files
:bn
:bp
:bl
:b
:ls vim
elvis :e# vi clone
Vim GUI Buffers
buffer
:bd(elete)
buffer vim
vim buffers
cache
:e!
vim :e!
:f Ctrl+g
:f
(file)
:r
(read)
:35 r
35
gf
vim word
24
6.3.
:-)
6.3
:q
(quit)
:q!
:wq
:x
ZZ
:x
:w
(write)
:q :q! vim
:qa :qa! vima all :! !
6.4 Vim
6.4.1 vim -x []
vim vim
6.4.2 vim :X
vim ..swp
ls -a
swp root :-)
swap :set noswf
swap
elvis /var/tmp/*.ses
Vim *.swp
-rw-------
25
6.5.
6.5
vim -r vim :recover
26
7.1
v
vcharacter visual v
v Esc
v-mode
Vline visual V
V Esc
v-mode
Ctrl+v
gq
ay
a ap
Shift+> Tab
Shift+< Tab
27
7.2.
:h visual.txt Tab
7.2
Ctrl+w n
:new
:sp(lit)
Ctrl+w f
word
Ctrl+w q
:q
Ctrl+w o
:only!
Ctrl+w j
Ctrl+w k
hjkl
:sp
X
rxvt + Vim Vim
28
8
shell
8.1 shell
:!
$PATH
:!!
@:
Vim
:sh(ell)
:r !commond
commond
:r !date elvis
:n,mw !commond
n m commond input
29
8.2.
8 shell
8.2
vi on-line help Vim elvis Vim
tag elvis HTML elvis
HTML
pe2(3) F1 Vim F1
elvis /.elvislib/elvis.rc
map #1 :helpM
M Ctrl+v M Enter M
M
M console Ctrl+Shift+v
:ver
+
elvis/nvi 1
:q pe2 F4
Vim
/.vimrc :q!
30
9
set
Vim Vim
Vim elvis
:h option-list
vimrc example.vim
9.1
9.1.1 Vim
:set ai :set noaiai autoindent
vim vim
/.exrc
/.vimrc
/.gvimrc
$VIM/vimrc
$VIM/gvimrc
$VIM\_vimrc
$VIM\_gvimrc
GUI
GUI
Windows
GUI $HOME/.vimrc
$VIM /usr/share/vim /usr/local/share/vim
$HOME/.bash profie $HOME/.bashrc Windows
$VIM C:\Vim autoexec.bat
31
9.2.
9 set
9.1.2 elvis
/.exrc
/.elvislib/elvis.rc
C:\Program Files\elvis\elvis.rc
Windows
9.1.3 nvi-m17n
/.exrc
/.nexrc
9.2
:set :se
:set all
:scriptnames
:set option?
option
:option
=
:set nooption :set
:set autoindent noconfirm autowrite
Vim :opt[ion]
set Enter
:q Enter
:mk[exrc]
:mkv[imrc]
/.exrc
/.vimrc
32
9.3. SET
9 set
9.3 set
Vim
autoindent[ai]
Enter
autowrite[aw]
background[bg] Vim
backup file
writebackup[wb] Vim
backup :h backup-table
backup backup
:ver
backupdir[bdir] Vim
backup file
33
9.3. SET
9 set
binary[bin] Vim
EOL
offelvis
16
ASCII
browsedir[bsdir] Vim
GUI GUI
[File] [Open]
cindent[cin] Vim
cmdheight[ch] Vim
compatible[cp] Vim
vi vim off
confirm[cf] Vim
off
directory[dir]
swap
fileformat[ff] Vim
EOL(end of line)
dos 0x0D0A
unix 0x0A
mac 0x0D
Linux unix
34
9.3. SET
9 set
fileformats[ffs] Vim
ff
:set ffs=unix,dos ff=unix
unix dos dos
dos unix :set ff=unix
unix
ff ffs unix dos
M 0x0D :set ff=unix
:%s/M//g M M M
Hey 0x0D M
ga 10168 a
ascii Vim elvis elvis dos
M
ignorecase[ic]
off
incsearch[is] Vim
word wrap
EOL 0 word wrap
wrapmargin[wm]
textwidth 0
35
9.3. SET
9 set
wrap
EOL
wrapscan[ws]
paste Vim
ruler[ru] Vim
Top
Bot
All
statusline[stl] Vim
:h stl
shiftwidth[sw]
>> Tab
tabstop[ts]
Tab 8
Vim softtabstop modeline
showcmd[sc]
36
9.4. SOFTTABSTOP[STS]
9 set
showmode[smd]
viusalbell[vb] Vim
beep
number[nu]
:nu
:# ruler
list
Taiwan XIM
xcin-2.5x xcin-2.3x XA multi byte
ansiset guifont set guifontset
history[hi]
20
9.4 softtabstop[sts]
OS Tab 8
8
37
9 set
Vim softtabstop
set softtabstop=4
set shiftwidth=4
4 Tab Tab vim 4
Tab Tab 12
Tab Space
8 Tab
Ctrl+v Tab Ctrl+v I 8 Tab
Tab :-)
ts=2
Tab Tab
vim :h
modeline
38
9.6.
9 set
1. modeline vim
sh script # vim: set modelines=0
2. vim
3. (sapce Tab )
/* vim:noai:sw=3 ts=4 */ => C /* vim
// vim:ts=2
=> C++
# vim:ts=2
=> sh script, perl, python, tcl
" vim:ts=2
=> vim script
9.6
set wrap
Vim :set linebreak(lbr)
EOL
( EOL )
1 \ TEX/LATEX %
TEX/LATEX EOL HTML
9.7
9.7.1 .vimrc
" /.vimrc by Edward G.J. Lee
" vim vim
" This code is Public Domain
"
set backspace=indent,eol,start
set autoindent
script script
1 Vim
39
9.7.
9 set
set history=50
set ruler
set showcmd
set enc=big5
" big5
" :update :w vi
map <F2> :up<CR>
map <F3> :up<CR>:q<CR>
"
map <F4> :q!<CR>
"
map <F5> :bp<CR>
" buffer
map <F6> :bn<CR>
" buffer
" <F7> syntax on/off Vim script
" <F7> on off on
"
map <F7> :if exists("syntax_on") <BAR>
\
syntax off <BAR><CR>
\ else <BAR>
\
syntax enable <BAR>
\ endif <CR>
" F8 searching highlight highlight
map <F8> :set hls!<BAR>set hls?<CR>
" Toggle on/off paste mode
map <F9> :set paste!<BAr>set paste?<CR>
set pastetoggle=<F9>
map <F10> <ESC>:read !date<CR>
"
map <F11> :%!xxd<CR>
" xxd 16
map <F12> :%!xxd -r<CR>
"
"Default backspace like normal
set bs=2
"Display a status-bar.
"set laststatus=2
"Show matching parenthese.
set showmatch
" :h hi
hi Comment
term=bold ctermfg=darkcyan
hi Constant
term=underline ctermfg=Red
hi Special
term=bold ctermfg=Magenta
hi Identifier
term=underline ctermfg=cyan
hi Statement
term=bold ctermfg=Brown
40
9.7.
hi
hi
hi
hi
hi
hi
hi
hi
hi
PreProc
Type
Ignore
Error
Todo
Search
ErrorMsg
StatusLine
StatusLineNC
9 set
term=bold ctermfg=DarkYellow
term=bold ctermfg=DarkGreen
ctermfg=white
term=reverse ctermbg=Red ctermfg=White
term=standout ctermbg=Yellow ctermfg=Red
term=standout ctermbg=Yellow ctermfg=Black
term=reverse ctermbg=Red ctermfg=White
ctermfg=darkblue ctermbg=gray
ctermfg=brown
ctermbg=darkblue
set viminfo=20,\"50
"
set formatoptions=mtcql
" modeline
" vim: ts=2:
9.7.2 .gvimrc
" /.gvimrc by Edward G.J. Lee
" This code is Public Domain
"
set mousehide
" mouse
map <S-Insert> <MiddleMouse>
map! <S-Insert> <MiddleMouse>
" Only do this for Vim version 5.0 and later.
if version >= 500
let c_comment_strings=1
if !exists("syntax_on")
syntax on
endif
hi
hi
hi
hi
hi
hi
hi
hi
hi
Comment
Constant
Special
Identifier
Statement
PreProc
Type
Ignore
Error
guifg=DarkBlue
gui=bold guifg=Magenta guibg=#fffff5f2eed8
guifg=Blue guibg=#fffff5f2eed8
gui=bold guifg=DarkCyan
gui=bold guifg=brown
gui=bold guifg=black
guifg=darkgreen
guifg=bg
guibg=Red gui=bold guifg=White
41
9.7.
hi
hi
hi
hi
hi
hi
hi
hi
9 set
Todo
guifg=Blue guibg=Yellow
ErrorMsg
guibg=Red gui=bold guifg=White
Normal
guibg=#fffff5f2eed8
ModeMsg
guifg=DarkBlue guibg=yellow
StatusLine
gui=bold guifg=lightgray guibg=DarkBlue
StatusLineNC gui=bold guifg=lightgray guibg=brown
Cursor guibg=green guifg=NONE
lCursor guibg=Cyan guifg=NONE
endif
" ex(:) mode (gvim)
set imcmdline
" xcin insert mode (gvim)
set imdisable
9.7.3 .vim
.vimrc .gvimrc
.vim $VIMRUNTIME .vim
10
Vim
regexp
:h pattern Un*x
man 7 regex man edman sedman grepman awkman perlre
regexp Vim perl regexp
perl :-) Vim
( Vim script )
10.1
*
0 0
\+
* 0
\=
0 1
\|
or \| pattern
\+, \=, \| \ Vim regexp +,
?, | \+
elvis ed \? 0 1 \=
43
10.1.
10
[] dg*
* g 0 0 d( 0 )dg, dgggg,
dgggggggg pattern /dg* pattern
extended d
:%s/dg*/test/g extended
extentestetest
shell pattern matching notation regexp dg* shell
dg d shell *
[] dg\+
dg, dgg, dgggggg d dg\= ddg
[] :%s/The\|All/test/g
The All test There
testre
[] /123-\=4567
1234567 1234567 123456789
[...]
[..]
[. . . ]
shell
? \ escape \. .
regexp \*
[]
[Aa]
A a
[12345]
12345 [15]
[09] 0 9 [ad] abcd
44
10.1.
10
[] W[0-9]*\.cc
W 09
cc W.ccW1.ccW2.ccW345.ccW8976543287.cc
W .cc
W[0-9][0-9]*\.cc
[] .*
[]
[M] M
[Tt] T t
[0-9]
[a-zA-Z]
$
$ $
[] /What
What Whatever, Whats
/What$ What
[] $
\(...\)
[] :%s/\([a-z]\)\1/test/g
aa, bb, cc, dd,. . . zz test :%s/[a--z][a--z]/test/g
aa, ab, ac. . . ba, bb, bc. . . zz test \(...\)
\1
45
10.1.
10
[] :%s/\(.\)\(.\)r\2\1/test/g
r
test\2 \(.\) \1 \(.\)
12r21cfrfc7grg7 test
\< word word
\> \< \> pattern
regexp
ed perl >b perl >bed >b \<, \>
perl ? regexp $
anchor patternword boundary
Vim \b <BS> Backspace
[] :%s/\<abbbc\>/test/g
abbbc test:%s/abbbc/test/g
deabbbcly abbbc test :%s/The\<All/test/g
:%s/\<The\>\|\<All\>/test/g There testre
[] :%s/\<abbbc/test/g abbbc (word)
abbbc test
abbbcabbbcerd abbbckijuds
\{n,m}
n m
46
:%s/[0-9]\{3,4}/test/g 112
3 12345 test5123456 test5612345678
testtest1234567 testtest1231234 test
gc confirm
u
[] \{}
xy\{20} x 20 y e[x-z]\{4} e x,y,z
exxxx, exyyz, ezzyz, exyzz
[] \{}
xy\{2,} x y xyyy* xyy\+
[] \{}
xy\{,4} x y x, xy, xyy ,xyyy,
xyyyy
Space Tab
\S
\d
digits [09]
\D
[09]
\w
\W
[09azAZ ]
\a
\A
[azAZ]
\l
\L
[az]
\u
uppercase [AZ]
\U
[AZ]
vi []
47
10.3.
10
10.3
:[range]g/pattern/[cmd]
:g/$/d
$
Space Tab
:g/[<Space><Tab>]*$/d
Vim elvis <Space><Tab> Tab
vi Ctrl+v Space Ctrl+v Tab
:g/\s*$/d
:-) 0 1
:%s/$//g :s
10.4 &
patern
48
10.5. GREEDY
10
[] :%s/\d\d\d\d\d\d\d\d\d\>/ID:&/g
ID: T123456789
ID:T123456789 \d [0-9]\u \>
T12345678999 \<ID:
TeL:
[] 3 7 2
:3,7s/.*/
&/
:3,7s/.\+/
&/
.* .\+ . * \+
[] 3 7 2
:3,7s/
//
[] Edward
:%s/\<Edward\>/[&]/g
[] Edward
:%s/\<Edward\>/\U&/g
\U \U pattern
[AZ]
\L :h
sub-replace-special
[] <BR> HTML tag
:%s/.*/&<BR>/g
regexp :-)
regexp
10.5 greedy
regexp pattern
greedy regexp
49
10.5. GREEDY
10
http://www.rtfiber.com.tw/changyj/
50
11
Vim folding
11.1
foldmethod[fdm] manual
11.1.1
zfzF:fo[ld]
zfap
zf7G
:3,9fold 3 7
5zF
Shift+v zf
51
11.2.
11 Vim folding
11.1.2
zo
open
zc
close
zr
reduce
zm
more
zR
zr
zM
zm
zi
zn
fold none
zN
zn
zn zR zR foldlevel
zn foldenable
Vim script
i o
dd
yy p
11.1.3
:mkview
:loadview
Vim script
11.2
52
11.2.
11 Vim folding
11.2.1
:set foldmethod=indent :set foldmethod=normal
11.2.2
:set foldmethod=expr :set foldexpr=... :h
fold-expr
11.2.3
syntaxset foldmethod=syntax
:h syn-fold
11.2.4
vimdiff vim -d file1 file2 foldmethod=diff
diff
11.2.5
marker {{{ }}}
C /* */ shell
script # Vim script
foldmarker
53
11.2.
11 Vim folding
:set foldmethod=marker
#!/bin/sh
# sh script
# {{{
script vim
# }}}
# vim:fdm=marker:ts=2
modeline 9 9.5 38
54
12
Vim tags
tag Vim
tag hyperlink
tag ctags
tags Vim
12.1 tag
ctags
ctags C
exuberant ctags C/C++JavaFortran
ctags --version
etags
emacs/xemacs
JTags
Java
ptags.py
Python
ptags
Perl
55
12.2. TAGS
12 Vim tags
12.2 tags
tag
tagname TAB tagfile TAB tagaddress term field
tagname
TAB
Tab
tagfile
tag
tagaddress Ex
term
;"
field
12.3 tag
source code
ctags -R *
source code tags -f
source code tags
ctags
ctags man ctags
ctags
Vim binary search
12.4 tag
tag files source code vim
tags :set tags=your.tags
tags Vim
Ctrl+] Ctrl+T
56
12.5. VIM
12 Vim tags
12.5 Vim
Vim tags tags
Ctrl+] Ctrl+T
12.5.1 doctags
$PATH Vim runtime/doc
tags doctags
** tag
source code runtime/doc
make doctags => doctags
make tags => *.txt tags
doctags *.txt $VIMRUNTIME/doc
12.5.2 Vim
vim :helpt[ags] *.txt tags
57
12.5. VIM
12 Vim tags
*test1*
*test2*
test.txt $HOME/.vim/doc
cd .vim/doc
vim -c "helptags ." -c quit
vim :h test1 F1
LOCAL ADDITIONS:
58
13
Vim script
vi macro
Vim Vim
vimrc syntax/plugin Vim script
vi macro
Vim script
:-)
13.1 macro
macro
13.1.1
Vim
9.7 39 Vim
F1
59
13.1. MACRO
13 Vim script
Vim
<Esc>
Esc
<Tab>
Tab
<Home> Home
<Del>
Del
<CR>
Enter
<Enter>
Enter
<LT>
<BS>
Backspace
<Up>
PageUp
<F5>
F5
<C-G>
Ctrl+G
vim :h key-notation
\< cpoptions B B
:set cpoptiions?
:set :autocmd
map
Visual mode
Insert mode
omap
Operator-pending mode
cmap
Command-line mode
13.1. MACRO
13 Vim script
bi{<Esc> b i {
Esc
e
a}<Esc>
append }
vim
Vim script
map ,b bi{<Esc>ea}<Esc>
,b , b Vim
1 b braces
:map
n normali insert
nore
:noremap
:vnoremap
:nnoremap
:onoremap
:noremap!
:inoremap
:cnoremap
=>
=>
=>
=>
=>
=>
=>
13.1.2
, b
Vim
61
13.1. MACRO
13 Vim script
3.1.2 11 1.4 4
:ia[bbrev]
:ab[breviate]
i
c
!
:ab gl
gl
:una[bbreviate] gl
gl
:ia[bbrev]
:ab
:cb[bbrev]
:ab
:norea[bbrev]
:abc[lear]
:ab
:iabc[lear]
:ia
:cabc[lear]
:ca
13.1.3
Vim
:com[mand][!]
[]
(1)
(2) :X:Next:Print
(3)
Vim script
62
13 Vim script
13.1.4
Vim ex
-nargs
-nargs=0
-nargs=1
-nargs=*
-nargs=?
-nargs=+
Tab <args>
<args>
<q-args> <args>
<f-args>
63
14
Vim
14.1
mutt/slrn
64
14.2.
14 Vim
14.2
14.3 TEX/LATEX
14.4 Java
65
15
Vim tips
tips
tips
66
Copyright
c 2000, 2001, 2002, 2003 Edward G.J. Lee
2003 3 3
GNU FDL http://www.gnu.org/copyleft/fdl.html
license
GNU FDL PDF Copyright
APL(Arphic Public License)
FDL
67
68
*, 43
, 5, 60
., 44
, 46
[..], 44
, 59
[0-9], 45
, 46
[M], 45
, 4
[Tt], 45
, 67
[a-zA-Z], 45
, 4, 60
[. . . ], 44
, 44
$, 45
, 46
&, 48
, 43
, 45
, 4, 60
\+, 43
, 48
\=, 43
, 2
\|, 43
, 60
\>, 46
, 46
\<, 46
, 2
, 47
, 59
, 46
, 5
, 5
, 50
, 5, 60
, 46
, 67
, 5
, 50
anchor pattern, 46
, 48
APL, 67
, 43
awk, 43
, 43
, 5
character classes, 47
, 51
cpoptions, 60
, 46
ed, 5, 43, 44, 46, 48
69
edline, 5
sub-replace-special, 49
elvis, 2, 44
syntax, 59
emacs, 2
tag, 55
escape, 44
tags, 55
esd, 5
ex, 5, 48
vi, 2
Ex , 5
word boundary, 46
FDL, 67
xmeacs, 2
folding, 51
globe, 48
greedy, 50
greedy , 50
grep, 43
help, 48
hyperlink, 55
license, 67
macro, 59
man, 43
metacharacter, 47
nvi, 2
nvi-m17n, 2
pattern, 43, 46
pattern matching notation, 44
perl, 46
perlre, 43
plugin, 59
regexp, 43
regular expression, 43
script, 59
sed, 43
shell, 44
70