Vim - incremental numbering via regular expression search and replace

拜拜、爱过 提交于 2019-11-28 13:09:15

I don't have an answer to your general question, but I do have one for your specific situation. You can make your command work by putting the comma into a positive look-ahead, like this:

:let i=1 | g/1(\,\)\@=/ s//\=i/ | let i+=1

Now it will only replace the 1.

A really easy solution:

:%norm f1s^R=line('.')^M

Obtained like this:

:%norm f1s<C-v><C-r>=line('.')<C-v><CR>

If you are not comfortable with typing complete macros on the command-line you can achieve the same result via recording:

qq
f1s<C-r>=line('.')<CR>
q
[range]@q
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!