强悍的 vim —— 删除空行、删除注释以及加注释解注释

强悍的 vim —— 删除空行、删除注释以及加注释解注释


原文 https://blog.csdn.net/lanchunhui/article/details/51588198


1. 删除空行
空行的构成比较复杂
(1) 删除没有内容的空白行
:g/^$/d
(2) 删除包含空格(%s) 的空白行
:g/^%s*$/d
2. 删除注释
:%s/^#.*$//g
如果某些行以若干空格开始,并以换行结束:
:%s/^[ ]*#.*\n//g
3. 删除以//开头的注释
$ cat test.txt | grep -v '//' >> test2.txt
4. 加注释
其实就是替换:
:s/^/#/
:s/^/#/g
末尾的g可加可不加
:s/<from>/<to> = substitude across entire document replacing <from> with <to>(只对每一行的第一个进行修改) 
:s/<from>/<to>/g = substitute every occurence on line rather than just first
5. 解注释
:s/^#//g
^#:表示开头为 # 号;


猜你喜欢

转载自blog.csdn.net/tty521/article/details/80733073