如何替换每行的前n个字符?

时间:2018-03-31 14:11:13

标签: vim

假设,我有

type,type,type,type,description,description,description.  
type,type,type,type,description,description.  

我想 -

type|type|type|type|description,description,description. 
type|type|type|type|description,description.  

我不知道文件的内容。我知道我必须用n替换,|替换每行final ImageButton btnTest =(ImageButton)findViewById(R.id.passVisibilityStatus); btnTest.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { btnTest.setSelected(!btnTest.isPressed()); if (btnTest.isPressed()) { btnTest.setImageResource(R.drawable.PassVisible); } else { btnTest.setImageResource(R.drawable.PassInvisible); } } });

3 个答案:

答案 0 :(得分:4)

没有任何软化,但它完成了工作

:%norm f,r|;.;.;.

击穿

:%norm       start a normal command on all lines
f,r|        f(ind) a ',' and r(eplace) with '|'
;.;.;.      ';' jumps to next match and '.' repeats the change

答案 1 :(得分:-1)

我想它可以解决你的问题

:%s/\v(type)./\1|/g

\v ......... very magic to avoid "\"
(type) ..... group 1
.   ........ any char (in our case ,)
\1 ......... back reference to group 1
| .......... literal |

答案 2 :(得分:-1)

使用宏 创建一个宏。在所有行上重复它。完成。