I have a markdown file with words like [this][], [that][], ... , and [the other][]. I know how to find these words in MacVim, but how do I replace them with [this][1], [that][2], ..., and [the other][n], where n is 26 in my case?
I'll also accept solutions using sed or awk or even Ruby if they prove to be simpler than using MacVim.
perl -p -i -e 's/(\[.*?\])\[\]/"$1\[".(++$i)."]"/ge' /path/to/file
Vim:
:let g:lastcount=0
:function PlusPlus()
let g:lastcount+=1
return g:lastcount
endfunction
:%g/./s/\V[\.\{-}][\zs\ze]/\=PlusPlus()/g
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With