次の例のように、ooooを1、2、3、...に変更したいと思います。
~から
> cat demo.snippet
snippet anova.cca "anova.cca fun"
anova.cca(
,${oooo:object}
${oooo:,...}
,permutations = ${oooo:how(nperm = 999)}
,by = ${oooo:NULL}
)
endsnippet
snippet adonis "adonis fun"
adonis(
,${oooo:formula}
,data = ${oooo:NULL}
,permutations = ${oooo:999}
)
endsnippet
snippet anosim "anosim fun"
anosim(
${oooo:,...}
,${oooo:grouping}
,permutations = ${oooo:999}
)
endsnippet
到着
snippet anova.cca "anova.cca fun"
anova.cca(
,${1:object}
${2:,...}
,permutations = ${3:how(nperm = 999)}
,by = ${4:NULL}
)
endsnippet
snippet adonis "adonis fun"
adonis(
,${1:formula}
,data = ${2:NULL}
,permutations = ${3:999}
)
endsnippet
snippet anosim "anosim fun"
anosim(
${1:,...}
,${2:grouping}
,permutations = ${3:999}
)
endsnippet
ベストアンサー1
Python(バージョン2または3)の使用:
from __future__ import print_function
oooo = None
with open('demo.snippet') as fp:
for line in fp:
if line.startswith('snippet '):
oooo = 1
while 'oooo' in line:
line = line.replace('oooo', str(oooo), 1)
oooo += 1
print(line, end='')
oooo
これは、1行で複数回発生した場合にも機能します。