How g makes loop in Vim ex command script

前端 未结 2 1345
没有蜡笔的小新
没有蜡笔的小新 2021-02-10 03:08

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:48

    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.

提交回复
热议问题