VIM学习笔记

据说vim才是程序员最爱的编辑器,抱着装逼的想法,我也要学一下。以后应该能用得着吧。这儿就做个简单的小笔记了。;-)
首先当然时进入vim啦,在shell中输入 vi [filename]
进去时是normal模式,按i可进入插入模式。这个i不就是insert的缩写嘛。然后Esc返回。这个光标移动总觉得怪怪的h(左)j(下)k(上)l(右)
退出时输入q,q!表示不保存,qw则是保存退出。
删除:x删除光标当前位置。 [number] d [object] 其中object包括w(word),e(…..),$(到本行结束)。注意:都是从当前光标位置开始。dd时删除整行。
修正:r 用于修改单个字符,后接要修改的字符。 [number] c [object] object和d的类似。p 将刚删除的字符(串)插入到光标之后。
u 撤销。U 恢复成原来的样子。 Ctrl + r 撤销。
vi里默认的注释颜色是蓝色,这完全看不清。在~/.vimrc中添加一句, 改成绿色:

hiComment ctermfg=6

颜色主要有这三种属性:

term
cterm// 设置为bold 则会很亮
ctermfg// 设置从1~8 种基本颜色

关于复制ctrl + v选中要复制的内容,然后y复制,移动光标到需要粘贴的地方,P粘贴,p为粘贴到下一行。

查找替换实例:

:s/foo/bar/g    
Change each 'foo' to 'bar' in the current line.
:%s/foo/bar/g
Change each 'foo' to 'bar' in all the lines.
:5,12s/foo/bar/g
Change each 'foo' to 'bar' for all lines from line 5 to line 12 (inclusive).
:'a,'bs/foo/bar/g
Change each 'foo' to 'bar' for all lines from mark a to mark b inclusive (see Note below).
:'<,'>s/foo/bar/g
When compiled with +visual, change each 'foo' to 'bar' for all lines within a visual selection. Vim automatically appends the visual selection range ('<,'>) for any ex command when you select an area and enter :. Also, see Note below.
:.,$s/foo/bar/g
Change each 'foo' to 'bar' for all lines from the current line (.) to the last line ($) inclusive.
:.,+2s/foo/bar/g
Change each 'foo' to 'bar' for the current line (.) and the two next lines (+2).
:g/^baz/s/foo/bar/g
Change each 'foo' to 'bar' in each line starting with 'baz'.

Note: As of Vim 7.3, substitutions applied to a range defined by marks or a visual selection (which uses a special type of marks ‘< and ‘>) are not bounded by the column position of the marks by default. Instead, Vim applies the substitution to the entire line on which each mark appears unless the \%V atom is used in the pattern like: :’<,’>s/\%Vfoo/bar/g.

阿,今天就学到这里了。重要的还是要多练习。在实战中记忆。教程的地址是:http://bbs.chinaunix.net/thread-2026233-1-1.html奋斗
http://vim.wikia.com/wiki/Search_and_replace

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值