比如下面一段文字:
强迫症患者,想要每行只显示一句话。可以在vim中按照如下2个命令搞定。
Having looked at the linux mtd/nand driver and more specific at nand_ecc.c
I felt there was room for optimisation. I bashed the code for a few hours
performing tricks like table lookup removing superfluous code etc.
After that the speed was increased by 35-40%.
Still I was not too happy as I felt there was additional room for improvement.
Bad! I was hooked.
I decided to annotate my steps in this file. Perhaps it is useful to someone
or someone learns something from it.
step1、逢点换行
命令:将【句点+空格】替换成【句点+换行】
:%s#\. #.\r#gc
释义+注意:
(1)【#】表示分隔符,用斜杠【/】也可以
(2)【\.】之后有个空格,即:【:%s#\.空格#.\r#gc】
(3)【\r】表示换行
(4)【%s】表示全局替换
(5)【gc】表示每次替换都询问是否确认替换。y:确认替换,n:不替换
step2、末尾非点,缩起下一行
命令:匹配【非点+$】
/[^.]$ #匹配【$】左边不是【.号】的行尾。---> 即:期望【.$】才是正确行尾。
J #缩起下一行
N #匹配下一个
. #重复J:缩起下一行
N #匹配下一个
. #重复J:缩起下一行
N
.
N
.
N
.
循环