How g makes loop in Vim ex command script

前端 未结 2 2092
长情又很酷
长情又很酷 2021-02-10 03:10

Consider the following Vim ex command,

:let i=1 | \'<,\'>g/^/ s/^\\ *-/\\=i/ | let i+=1

It replaces the heading dash with ordered number

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-10 03:25

    This is the general pattern of a :global command:

    :g/foo/command
    

    Because everything after the second separator is considered as one command, the counter is incremented each time the command is executed: one time for each matching line.

提交回复
热议问题