:%s/--\([a-zA-Z0-9]*\).\(.*\)--/--\1.\2.\1--/gc
或不要求每次更换确认:
:%s/--\([a-zA-Z0-9]*\).\(.*\)--/--\1.\2.\1--/g
将产生:
--something1.something2.something1--
--anotherThing1.something2.anotherThing1--
从:
--something1.something2--
--anotherThing1.something2--
这是如果您想将“--”之后的第一个单词复制到第一个“。”。并附加“。” 和在最后一个“--”之前找到的单词。
使用 vim。
重新评论:
有人提到当有多个单词时它会不起作用等等。我在以下方面对其进行了测试:
start of text file:
--something1.something2.something3.something4.something5.something6--
--anotherThing1.something2.anotherThing3.anotherThing4.anotherThing5--
end of text file:
用上面的表达式替换后:
start of text file:
--something1.something2.something3.something4.something5.something6.something1--
--anotherThing1.something2.anotherThing3.anotherThing4.anotherThing5.anotherThing1--
end of text file: