vim+神技 (1)

24
2011/10/14

Upload: ailsa126

Post on 02-Jul-2015

17.247 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Vim+神技 (1)

20

11

/10

/14

冒顿

Page 2: Vim+神技 (1)

小调查

• Vim 用户数?

• Vim 龄?

3 个月+

• 知识面

10 个技巧、30 个技巧+、通读 Vim doc.

Page 3: Vim+神技 (1)

简介

• 我的故事(三遇始识君)

• 编辑模式

• 编码设置

Page 4: Vim+神技 (1)
Page 5: Vim+神技 (1)
Page 6: Vim+神技 (1)
Page 7: Vim+神技 (1)

:h tutor

Page 8: Vim+神技 (1)

大纲

• 光标移动 (motion)

• 命令 (:command)

• 搜索&替换 (find, subst)

• 量词 [count]

• 文本对象 (text-object)

• 寄存器 (register)

• 标记 (mark)

• 列模式

• 配置 (vimrc)

• 插件 (plugin)

Page 9: Vim+神技 (1)

光标移动

• j k h l• w b e• 0 ^ $• H M L• gg G 50%• :50• %• <C-f> <C-b> <C-e> <C-y>• <C-o> <Tab>• gj gk gf gd :h g• :help motion.txt

Page 10: Vim+神技 (1)

trike

j

oh

q

gg

助记

ppenda

dd

zz ZZ

[[ ]]

eforeb

hangec

nde

indf

nserti

k

l

arkm

extn

astep

eplacer

illt

s

ndou

isualv

ordw

anky

x

eleted

cc

enz

yy

otog

Page 11: Vim+神技 (1)

trike

oin

ey

ow

igh

J

OH

Q

助记

ppendA

zz ZZ

( )

eforeB

hangeC

ndE

indF

nsertI

K

L

idM

extN

asteP

eplaceR

illT

S

U

isualV

ordW

ankY

X

eleteD

enZ

yy

otoG

{ }

Page 12: Vim+神技 (1)

trike

j

o

h

q

助记

ppenda

(

[[

eforeb

hangec

nde

indf

nserti

k

l

arkm

extn

astep

eplacer

illt

s

ndou

isualv

ordw

anky

x

eleted

enz

otog

Mode Motion

Edit

Search

Buffer

Others

*

#

0

^

%

{

)

]]

}$.

, ;

Esc

/

?

Page 13: Vim+神技 (1)

键盘映射

• == gg=G

• >> >G 2<<

• zc zo

• 自定义键盘映射

,cc <F3> ( <C-t> <M-1>

• :h map.txt

Page 14: Vim+神技 (1)

量词

• 5j 3w 2dd 3cw 2fa

• 10>> 8== 4Y 4yp

• 50% 100gg 100G

• :h count

Page 15: Vim+神技 (1)

命令

• :h :help

• :wq

• :qa!

• :bro w [file.name]

• :new :vnew :tabnew

• 自定义命令– :Cal :MRU :Uisvr css

• :h command

Page 16: Vim+神技 (1)

搜索&替换

• / ? n N– 支持正则表达式

– :set hls :noh

• * #

• f F t T ; ,

• :%s/key/word/g

• :%s/key//n

• :vimgrep /key/

• :h pattern.txt

Page 17: Vim+神技 (1)

文本对象

• inner object

– viw ci” di(

• an object

– yaw cat dap

• :h text-object

Page 18: Vim+神技 (1)

寄存器

• “add “bY “ap “bp

• 无名寄存器 “”

• 命名寄存器 a-z

• 编号寄存器 0-9

• 黑洞寄存器 _

• 系统剪贴板 + :set clipboard+=unnamed

• :h registers

Page 19: Vim+神技 (1)

标记

• ma mb

• ‘a ‘b

• `a `b

• :h mark

Page 20: Vim+神技 (1)

列模式

• <C-v> (for *inx)

• <C-q> (for Windows)

• :h ctrl-v

Page 21: Vim+神技 (1)

配置参考

• https://github.com/vingel/vim

• https://github.com/janlay/vim

• https://github.com/cnruhua/macvimfiles

• https://bitbucket.org/leeiio/vim

• https://github.com/lilydjwg/dotvim

• https://github.com/hotoo/vimrc

Page 22: Vim+神技 (1)

插件

• https://github.com/msanders/snipmate.vim• https://github.com/scrooloose/nerdtree• http://vim-taglist.sourceforge.net/

– http://www.vim.org/scripts/script.php?script_id=273

• https://github.com/majutsushi/tagbar– http://www.vim.org/scripts/script.php?script_id=3465

• https://github.com/vim-scripts/mru.vim– http://www.vim.org/scripts/script.php?script_id=521

• http://code.google.com/p/vimwiki/• https://github.com/hotoo/uisvr.vim• https://github.com/hotoo/template.vim• https://github.com/hotoo/more.vim

Page 23: Vim+神技 (1)

尾声

• 宏 :h q

• 持久化撤销 :h undo

• 版本比较 :diff

• 相对行号 :h rnu

• 语法高亮 :h syntax

• 外观皮肤 :h colorscheme

• 代码折叠 :h folds

• 自动缩进 :h indent

• 智能补全 :h omni-completion

• 会话恢复 :h sessions

• 文件自动备份与紧急恢复 :h backup

• …

Page 24: Vim+神技 (1)

小众