Some questions about substitution, to the following text segment:
add_port state M1/PDDS -state {m1 1.0} -state {m2 0.9} -state {m3 off}
create_pst pst1 -supplies {SW1/sout M1/PDDS}
add_pst_state state1 -pst pst1 -state {0.7 0.9}
add_pst_state state2 -pst pst1 -state {0.8 0.9}
add_pst_state state3 -pst pst1 -state {0.8 1.0}
add_pst_state state4 -pst pst1 -state {off off}
# explicit directive to say no isolation
set_isolation iso1 -domain PDM -no_isolation
I can use :%s/^.*\n// or :g,^,d to delete all lines, while why I
can not delete all lines by :g,^,s/^.*\n// or :g,add,s/^.*\n// to
delete all lines containing word “add”
I am confuse about this? Would someone give me some explanations, and
can you recommend some useful tips about the “global” command in vim?
Thanks very much.
Some questions about global substitution
-
- 帖子: 2
- 注册时间: 2009-03-16 18:02
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: Some questions about global substitution
你用 :s 把一行干掉之后,后面的那行变成当前行。但 :g 已经处理过当前行了,于是它去找下一个标记的行去了。Vim 手册 写了: global 命令先扫描 [range] 界定的行,然后对每个匹配的行进行标记 (对于一个跨行的
匹配,则只针对开始的一行)。
第二次扫描对每个标记的行,并在其之前附加上行号,执行指定的 |cmd| 命令。 ":v"
和 ":g!" 命令针对未标记的行进行。如果一行被删除,其标记也自动消失。
缺省的 [range] 是整个缓冲区 (1,$)。用 "CTRL-C" 中断该命令。如果某行的执行给
出错误,该行的执行被中断,但 global 命令仍从下一个被标记或未被标记的行继续。
隔行删除的好方法
