forum.suse.org.cn web view20.12.2008 ·...
TRANSCRIPT
12233 Vim4444Vim4555Vim~/.vimrc6Vimrc6Vimrc6VIM6Vim 7Vim7Vim7 91929310410 115116117118NN1191210121112 1312CTRL-0CTRL-I13131314Vim14151416Vim15171518ctags1619Vim17 2020202120222023212421 22252226//222722282329233023312332.()24332434:g25 2735273627372738283928403041314231 Vim3443Vim34443445VimUnix354635473548CTRL3649Vim36 Vim37583759Swap3760Vim37 gVim3864gVim3865gVim3866gVim39 Vim40674068 4069Vim417041 Vim4371N43724373437444754476Vim4477Vim4578VimUnix Shell4579vimdiff4680Vimmap4681BashVim4782Vim4783Vim478447854886Vim48 50875088/50895090125191vimgrep53925393Vim5494:match54 55955596559756985699561005810159 611612Vim623Vim62462562662763863963106311Vim ex64126413ASCII6414Vim64156466
VIM 101 Hacks www.thegeekstuff.com
--Franz Kafka
UnixLinuxVi/VimVim
101VimVim
Vim
15
1Vim
214 101
15
CTRL-A CTRLA
10j
:set nu
Ramesh NatarajanGeek Stuffthegeekstuff.com
CLinuxDBAEMC
passworlddragon.com WindowsLinuxMAC
Linux 101 Hacks
http://www.thegeekstuff.com/linux-101-hacks-free-ebook/
http://www.thegeekstuff.com/contact
c2009 Ramesh Natarajan
XiuJuan Lu([email protected])
Vim
VimVim
Vim
--Prof. Dr. Fritz Mehner, Fh Sudwestfalen
VimbashVim
1.0
20091021
Vim
101Vim
/etc/passwd
1
$ vim /etc/passwd
2VimVim
$ vim
:e /etc/passwd
:w :write
:up :update
:w newfile.txt
newfile.txt
:up newfile.txt
newfile.txt
:w! newfile.txt
newfile.txt()
:up! newfile.txt
newfile.txt()
Vim
:x
:wq
ZZ
:q!
:qa
Vim
Vim
Vim
Vim
Normal
Vim
Insert
Command Line
:wq
Hello World!helloworld.txt
1
$ vim helloworld.txt
2Hello World!
i
3:wq
:wq
Vim
Visual
vVCTRL-VVim
Select
:help vim-modes-intro
SELECT
Ex
:help vim-modes-intro
Ex
Vim
j
k
h
lL
ADM-3AhjklUnix
jkhl
Vim~/.vimrcVimrc
VimVim
Vim:set numberVimVim
Vim~/.vimrc
$ vim ~/.vimrc
set number
set list
vimrc
UNIX/Linux
$HOME/.vimrc
/home/Ramesh/.vimrc
Unixvimrc.()
Windows
$HOME/_vimrc
C:\Documents and Settings\ramesh\_vimrc
Windowsvimrc_()
Vimrc
vimrcVimvimrc
vimrc
UNIX/Linux
$VIM/.vimrc
/usr/share/vim/.vimrc
Windows
$VIM/_vimrc
C:\Progrom Files\Vim\_vimrc
VIM
Vim7.2
Vim:versionVim
UbuntuVim
$ vim
:version
WindowsVim
C:\> vim
:version
Vim
VimUnixVim
WindowsVim
vim.org->Download->PC:MS-DOS and MS-Windows->Self installing executable-> gvim72.exe
ftp://ftp.vim.org/pub/vim/pc/gvim72.exe
gvim72.exe
Ubuntu LinuxVim
$ sudo apt-get install vim-full
Vim
:helpVim
$ vim
:help
Vim
||
||CTRL-]
|quickref|
:help :h
Vim
:helpgrep pattern
:helpgrep saveas
:cn
:help option
Vim
:help list:set list
:help CTRL-X
Vim CTRL-X
CTRL-Vim
:help :x
Vim :x
:Vim
:help
:help
Vim
VimtutorVim
vimtutor
$ vimtutor
vimtutor
$ vimtutor es
hjkl
1
jkhl
CTRL-F
Front
CTRL-B
Bottom
CTRL-D
Down
CTRL-U
Up
jkCTRL
jkCTRL
CTRL-E
CTRL-Y
2
hl
w
W
WORD
e
E
b
B
(word)WORD
WORD
192.168.1.37word192.168.1.3WORD
192.168.168.1.3 devserverwword.()192word
192.168.168.1.3 devserverWWORDdevserverd192.168.1.3WORD
wordWORD
3
lh
0zero
$()
^()
g_
4
{
}
[[
]]
(
)
5
H
Hhome00
M
L
6
z
z-z
z.(z)
7
:0
-1
gg
-2
1G
-3
:$
-1
G
-2
8NN
50%
50%
75%
75%3/4
100l
100l100
100
100
100
:goto 25
25
25|
2525
9
Vim
:set number
:set nu
:set nonumber
:set nonu
:set numberwidth=5
4numberwith5
:50
50
50gg
50
50G
50
10
VimShell
Unix
%
(){}[]
[(
(
[)
)
[{
(
[}
)
11
wWShitf
wi
Windowsgvim
SHIFT-
SHIFT-
12CTRL-0CTRL-I
Vim
:jumps
CTRL-0
CTRL-I
5CTRL-0
05
5CTRL-I
05
names.txt
vim names.txt
:jumps
jump line col file/text
3 484 19 /home/ramesh/scsi-list.txt
2 5 0 /etc/passwd
1 6 19 /etc.yp.conf
> 0 16 51 John Smith
1 10 7 /etc/sudoers
2 4 3 /etc/group
3 204 3 /home/ramesh/my-projects.txt
names.txt:jumps
location 0>
names.txtlocation0>0 16 61 Jonh Smth
/etc/passwordlocation22CTRL-0
/etc/grouplocation 22CTRL-I
13
Vimj
5
gj
gk
g^
g$
gm
14Vim
$ vim +142
143
$ vim +/search-term
$ vim +?search-term
$ vim -t TAG
TAG
/etc/passwdjsmith/etc/passwdjsmith
$ vim +/^jsmith /etc/passwd
15
ma
a
`a( a)
a
a( a)
a
m{mark-name}mark-name
m{makr-name}
Vim
maama
VimViUNIX
1`{mark-name}
`aa
2{mark-name}
aaCustonLog logs/access_log combined
a
16Vim
vim
1 : /etc/passwd /etc/group
2 /etc/passwdmPP
3 :n/etc/passwd/etc/group
4 /etc/groupmGG
5 `PP/etc/passwd
6 /etc/passwd`G(+G)/etc/group
Vim:set autowrite
17
:marks
:marks
a a159line15yp.conf
b b1118line18yp.conf
G Ggourp560
P Ppasswd490
Vim:marks[]^.Vim
:marks
`
`[
`]
p/p
p>
.
^
Vim
ma a
`a a
a a
:marks
:marks a a
`.
.
18ctags
ctags
apt-get install exuberant-ctags
rpm -ivh ctags-5.5.4.1.i386.rpm
ctags
C~/src
cd ~/src
ctags *.c
Ctagstags*.ctagsctags
cat tags
1ta
:ta mainmycpgropram.cman
vim mycpgrogram.c
:ta main
2CTRL+]
CTRL+]
ssh_xcallocCTRL+]ssh_xcalloc
vi mycpgrogram.c
av = ssh_xcalloc(argc, sizeof(char*));
ctagsvimE246 tag not found ssh_xcalloc
3CTRL+T
CTRL+]CTRL+T
4
:ta getVimget
vim mycprogram.c
:ta /^get
Vimtag
Vim
:ts
:tn
:tp
:tf
:tl
19Vim
tagsVimtaglistVim
VimtaglistYegappan Lakshmanan
TagListVim
VimTaglist
vim.orgVimTaglist
$ cd ~
$ wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701
Taglist Vim
$ mkdir ~/.vim
$ cd ~/.vim
$ unzip ~/taglist.zip
~/.vimrc
$ vim ~/.vimrc
filetype plugin on
taglistctagstaglistctags
1Vim:TlistOpenTagList
vim mycprogram.c
:TlistOpen
Vim:TlistOpen
TagList
2
3
1ctagsCTRL+]Tag
2VimVimTagTagVim
3/
TagspaceVim
Tagdbd_constructVim
5
Tagspacefunction
20
i
I
IIndia
o
oorange
O
OOrange
:r FILENAME
:r! COMMAND
:r! date
WindowsdatetimegVim
A
A
21
r{c}
{c}
R
A
22
s
S
4s
4
4S
4
$ vim employee.txt
100 John Doe DBA
200 John Smith Sysadmin
300 Raj Patel Developer
John DeoD2sDo
2S12
23
cc
S
C
24
J
J
J
:set nojoinspaces
25
y>filename
:g/^/m0
:g:/^\s*PATTERN/exe norm!|/*
\A */\
C/**/
:g!:v
employees.txt
$ vim employees.txt
Emma Thomas:100:Marketing
Alex Jason:200:Sales
Madison Randy:300:Product
Development Sanjay Gupta:400:Support
Nisha Singh:500:Sales
Sales
:g/Sales/d
Sales
:g!/Sales/d
:v/Sales/d
35
yank
az26
ayy
a
a5yy
5a
ap
a
aP
a
36
Vimjohn
johnJason
cwjasonjohn
johnJason
.vimrc
$ cat ~/.vimrc
inoremap U@.
@.
37
US