vim+神技 (1)
TRANSCRIPT
20
11
/10
/14
冒顿
小调查
• Vim 用户数?
• Vim 龄?
3 个月+
• 知识面
10 个技巧、30 个技巧+、通读 Vim doc.
简介
• 我的故事(三遇始识君)
• 编辑模式
• 编码设置
:h tutor
大纲
• 光标移动 (motion)
• 命令 (:command)
• 搜索&替换 (find, subst)
• 量词 [count]
• 文本对象 (text-object)
• 寄存器 (register)
• 标记 (mark)
• 列模式
• 配置 (vimrc)
• 插件 (plugin)
光标移动
• 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
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
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
{ }
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
/
?
键盘映射
• == gg=G
• >> >G 2<<
• zc zo
• 自定义键盘映射
,cc <F3> ( <C-t> <M-1>
• :h map.txt
量词
• 5j 3w 2dd 3cw 2fa
• 10>> 8== 4Y 4yp
• 50% 100gg 100G
• :h count
命令
• :h :help
• :wq
• :qa!
• :bro w [file.name]
• :new :vnew :tabnew
• 自定义命令– :Cal :MRU :Uisvr css
• :h command
搜索&替换
• / ? n N– 支持正则表达式
– :set hls :noh
• * #
• f F t T ; ,
• :%s/key/word/g
• :%s/key//n
• :vimgrep /key/
• :h pattern.txt
文本对象
• inner object
– viw ci” di(
• an object
– yaw cat dap
• :h text-object
寄存器
• “add “bY “ap “bp
• 无名寄存器 “”
• 命名寄存器 a-z
• 编号寄存器 0-9
• 黑洞寄存器 _
• 系统剪贴板 + :set clipboard+=unnamed
• :h registers
标记
• ma mb
• ‘a ‘b
• `a `b
• :h mark
列模式
• <C-v> (for *inx)
• <C-q> (for Windows)
• :h ctrl-v
配置参考
• 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
插件
• 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
尾声
• 宏 :h q
• 持久化撤销 :h undo
• 版本比较 :diff
• 相对行号 :h rnu
• 语法高亮 :h syntax
• 外观皮肤 :h colorscheme
• 代码折叠 :h folds
• 自动缩进 :h indent
• 智能补全 :h omni-completion
• 会话恢复 :h sessions
• 文件自动备份与紧急恢复 :h backup
• …
小众