vim in practice (0)

Skill

合并两行技巧

普通模式下(n),光标在上一行,
使用 (J) : 合并有一个空格
使用 (gJ):合并没有空格

写文档,加行号

:%s/^/\=printf('%3d  ', line('.') )
 %s!nl ( nl 表示 number line )

替换一个单词

cw

编辑buffer或者文件

:bn(next)
:bp(prev)

重复命令

.   重复以上命令
N . 重复以上命令N次

录制宏

qa -> 进入宏录制
Yp -> 复制一行进行粘贴
<C-a> (这里我将其替换为<A-a> 实现递增,因为windows会使用惯用键) -> 实现递增
q  -> 退出宏录制
@a -> 将寄存器记录重发
@@ 重复上一个操作

关于tabedit使用

set guitablabel=%N/\ %t\ %M  -> tab上面会显示 1/ name.suffix 的格式
map <C-tab> gt -> gt表示切换tab标签

查找当前word对应的匹配项

% : 到对应的 (, {, [.
* (resp. #) : 到对应的 (resp. previous) 光标标识的单词

在当前行进行定位

0 → go to column 0
^ → go to first character on the line
$ → go to the last character on the line
fa → go to next occurrence of the letter a on the line.
, (resp. ;) will seek for the next (resp. previous) occurrence.
t, → go just before the character ,.
3fa → search the 3rd occurrence of a on this line.
F and T → like f and t but backward.

如何让Dos下编写的文件在*nix下正常显示

一般DOS的换行符是\r\n(CRLF),而*nix则是\n(LF)
也就是Ctrl-v Ctrl-l
:%s/^M//g 去除^M,记住^M不是字面上,而是通过输入Ctrl-v enter打出来的