vim get start_1.0
DESCRIPTION
vim的入门教程,欢迎讨论。TRANSCRIPT
--- 龙浩
技术部:龙浩Twitter : hoorace版本: V1.0
来自?来自?
Vim 作者: Bram Moolenaar( http://www.moolenaar.net/ )http://en.wikipedia.org/wiki/Bram_Moolenaar
Vi 作者: Bill Joy在 sun 工作时间 1982-2003http://en.wikipedia.org/wiki/Bill_Joy
Why Vim ?Why Vim ?
速度定制性
中文支持无处不在
装逼需要
键盘图?键盘图?
你怎么看?你怎么看?
角度不一样,结果不一样!
Vim 的工作模式Vim 的工作模式
正常模式 (normal)
插入模式 (insert)
可视模式 (visual)
命令行模式( command ) 选择模式( select ) Ex 模式
基本命令基本命令
vim filename
i , a , I , A , o ,O
:w , w!
:q , :q! , :qa
Sex
:! python f:/test.py
:r! python f:/test.py
基本移动基本移动
h , j , k , l
Ctrl + d , Ctrl + u
Ctrl + f , Ctrl + b
高级移动高级移动
0 数字 0 ,不是字母 o , ^ , $ , gg , G , %
w , W , e , E , H , M , L
n| , :n
( , ) , { , } , [ , ]
zt , zb , zz
高级移动高级移动
gg , ggdG , ggvG , ggyG
Ctrl + i, Ctrl + o
标记标记
m<letter>
‘<letter>
`<letter>
‘. 跳转到上次修改的标记行 `. 跳转到上次修改标记处 `` 两个位置切换 m` 跳到任何地方, `` 返回
提示: Ctrl + o , Ctrl + I 是操作历史的前进返回,不是跳转。提示: Ctrl + o , Ctrl + I 是操作历史的前进返回,不是跳转。
编辑编辑
i , a , o , I , A , O
J , %j , 5J
dd , dw , D , 6dd
x , 3x
yw , yy , p , P
ciw , ci”, ci( , cc
修改, 还原修改, 还原
r , R U, u Ctrl + r
查找,替换查找,替换
/ , ? , * , #
n 或 N
:s/p1/p2/geci #g 表示整行替换, c 表示询问, i 表示忽略大小写 , e 不显示 error
:n1,n2s/p1/p2/geci
:%s/p1/p2/geci
列操作列操作
v , V
Ctrl + v
Textmate 风格多列插入:命令状态Ctrl-shift-v 选择列, shift-i 插入,结束后用 <esc>
简单重排简单重排
<< , >>
ce(nter) , ri(ght) , le(ft)
gqap # 整段重排 gqq # 本行重排 gqQ # 全文重排 gq3q # 重排三行 gq2ap #重排兩個段落
文本对象文本对象
aw, aW - ambient word or WORD (see docs)
iw, iW - inner word or WORD (see docs)
as, is - ambient or inner sentence
ap, ip - ambient or inner paragraph
a{, i{ - whole {..} block or text inside it
a(, i( - whole (..) block or just text inside it
a<, i< - whole <..> block or just text inside it
a[ , a ] , a” , a’, a` , i”, i’, i`
还记得 ciw 么? daw , yaw
视窗操作视窗操作
Ctrl+w n 即 :new 。开启一个新视窗Ctrl+w s 即 :sp(lit) ,左右切分视窗Ctrl+w f 开启一个新视窗,编辑鼠标所在处 word 为文件名的文件。Ctrl+w q 即 :q 结束分割出来的视窗Ctrl+w o 即 :only! 鼠标所在视窗为唯一视窗Ctrl+w j 移至下个视窗Ctrl+w k 移至上个视窗, hjkl 的方式
split 水平切屏vsplit 垂直切屏
自动化自动化
Ctrl - N , Ctrl - p # 自动补全Ctrl - E , Ctrl - Y # 复制前后一行的字符Ctrl - X , Ctrl - K # 字典补全Ctrl - X , Ctrl - L # 整行补全Ctrl-X Ctrl-N # 根据当前文件里关键字补全 Ctrl-X Ctrl-T # 根据同义词字典补全Ctrl-X Ctrl-I # 根据头文件内关键字补全 Ctrl-X Ctrl-] # 根据标签补全 Ctrl-X Ctrl-F # 补全文件名 Ctrl-X Ctrl-D # 补全宏定义
自动化自动化
Remap<Tab>
“ Insert <Tab> or complete identifier“ if the cursor is after a keyword characterfunction MyTabOrComplete()let col = col('.')-1if !col || getline('.')[col-1] !~ '\k'return "\<tab>"elsereturn "\<C-N>"endifendfunctioninoremap <Tab> <C-R>=MyTabOrComplete()<CR>
折叠 (*)折叠 (*)
zf , zc , zC , zo , zO , zj , zk , [z , ]z
zd , zD , zE
zR , zM
set fdm=*****manual # 手工定义折叠indent # 更多的缩进表示更高级别的折叠expr # 用表达式来定义折叠syntax # 用语法高亮来定义折叠diff # 对没有更改的文本进行折叠marker # 对文中的标志折叠
Shell 命令Shell 命令
:! , :!! , @: ,
:sh(ell)
:r !command , :r ! ls
n,nw !command
标签页标签页
:tabnew aa.txt
:tabp , :tabn
修改相关配置" shift tab pagesmap <S-Left> :tabp<CR>map <S-Right> :tabn<CR>
基本设置基本设置
文件放在 ~/.vim 文件夹中 filetype plugin on, filetype indent on
.vimrc 设置.vimrc 设置
set nocompatible " choose no compatibility with legacy vi
syntax enable
set fileencoding=utf-8,usc-bom,gbk
set showcmd " display incomplete commands
filetype plugin indent on " load file type plugins + indentation
set number
set cursorline
set history=1000
.vimrc 设置.vimrc 设置
"" Whitespace
set nowrap " don't wrap lines
set tabstop=4 shiftwidth=4 " a tab is two spaces (or set this to
4)
set expandtab " use spaces, not tabs (optional)
set backspace=indent,eol,start " backspace through everything in
insert mode
.vimrc 设置.vimrc 设置
"" Searching
set hlsearch " highlight matches
set incsearch " incremental searching
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one
capital letter
正则正则
\
\{n,m}
^$
:g/^[<Space><Tab>]*$/d
%s/aa/bb/g
键盘映射键盘映射
< Esc > Esc 键< Tab > Tab 键< Home > Home 键< Del > Del 键< CR > Enter 键< Enter > Enter 键,和上面的相同< LT > 就是 < ,在和 < 字元本身会有混淆、疑义时使用。也可以使用 \<
< BS > Backspace 倒退键< Up > PageUp 向上翻页键< F5 > F5 功能键< CG > Ctrl+G 键
键盘映射键盘映射
v map 仅在反白模式时作用, Visual mode 。 n map 仅在常态模式时作用, Normal mode 。 i map 仅在插入模式时作用, Insert mode 。 o map 仅在操作等待模式时作用, Operator-pending mode 。 c map 仅在命令列模式时作用, Command-line mode 。
键盘映射键盘映射
imap <C-tab> :tabnext<CR>
nmap <C-tab> :tabnext<CR>
imap <C-S-tab> :tabprevious<CR>
nmap <C-S-tab> :tabprevious<CR>
imap <M-1> <Esc>:tabfirst<CR>
高级功能高级功能
缓冲区 自动命令 Ptags , Ctags
案例: Python 编码环境搭建案例: Python 编码环境搭建
./configure --with-features=huge --enable-pythoninterp=yes
vim 的 autoload 下面存在 pythoncomplete.vim 这个文件 .vimrc 中添加记录:
1. filetype plugin on
2. autocmd FileType python set
omnifunc=pythoncomplete#Complete
此时, 按下 Ctrl+x, Ctrl+o , 就能看到提示列表框,以及对应的 docstring , Ctrl+n, Ctrl+p 来上下选择, ESC 来取消提示框。
经验经验
动手才是最关键的 , 熟能生巧! 有些东西需要死记硬背! 有一个量子跳跃期!
参考资料参考资料
http://www.vim.org
http://edt1023.sayya.org/vim/node1.html
http://vimdoc.sourceforge.net/htmldoc/motion.html#text-objects
http://edyfox.codecarver.org/html/_vimrc.html
http://www.slideshare.net/ZendCon/vim-for-php-programmers-presentation
http://www.moolenaar.net/habits.pdf
https://github.com/tpope
Q&AQ&A
个人一小步,产品一大步!