Home  >  Q&A  >  body text

How to modify vim's command to add the ; symbol and complete the line break at the same time?

Change this

flip   翻转[左右变成右左] fork   叉子\分岔\岔口\复刻
Convert

to

flip   ;翻转[左右变成右左] fork   ;叉子\分岔\岔口\复刻

I use

:%s/^\([ a-zA-Z]\+\)\([\U4E00-\U9FFF ]\+.\+\)\([ a-zA-Z]\+\)\([\U4E00-\U9FFF ]\+.\+\)$/; ;/g

Now I want

flip   翻转[左右变成右左] fork   叉子\分岔\岔口\复刻

become

flip   ;翻转[左右变成右左] 
fork   ;叉子\分岔\岔口\复刻

How to modify the vim command to complete the line break while adding the ; symbol?

某草草某草草2712 days ago713

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 16:36:35

    :s/^\([ a-zA-Z]\+\)\(\([\U4E00-\U9FA5]\+[^ ]*\)\+\)\([ a-zA-Z]\+\)\(\([\U4E00-\U9FA5]\+[^ ]*\)\+\)$/;\r;/g

    There are two more brackets
    PS: For Chinese matching, there is a method using [^ -x]1 on the Internet. The test found that it works, but I don’t know the principle.
    If there are no English or spaces in the Chinese explanation, you can write it more simply

    \(\([\U4E00-\U9FA5]\+[^ ]*\)\+\)
    #可以修改为:
    \([^ a-zA-Z]\+\)\+

    1. https://www.oschina.net/quest... ↩

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-16 16:36:35

    You can add a map to map ; to ;<CR>

    For example: inoremap ; ;<CR>

    reply
    0
  • Cancelreply