vim inserting increasing number

 

Substitute with ascending numbers

Suppose you want to replace each occurrence of "abc" with "xyz_N" where N is an ascending number (xyz_1, xyz_2, xyz_3, and so on).

One approach uses the following command:

:let i=1 | g/abc/s//\='xyz_'.i/ | let i=i+1

However, this only changes the first abc on each line. Adding the g flag for a global substitute does not help as i is only incremented once per matching line.

你可能感兴趣的:(vim)