I modifying a gcode file with custom toolswap codee, and I need to replace every instance of "T0" (^T0$) with a large amount of text (19 lines), which is stored in a separate file. How can I do so quickly?

There are about 100 instances that need replacement, and I can see the need to do more in the future, so I need something that does it all at once.

I tried defining a macro with q to replace one instance, hoping to run it a certain number of times, but I could only run the macro once. The macro deleted the line, and then read (:r) from the other file.

1 Answer 1


Does that work for you?


It will replace every occurence of T0 with the content of filename.

  • Thanks! That did exactly what I needed. I wasn't familiar with this type of syntax. Would you know where it is documented? Commented Mar 8, 2019 at 1:51
  • 2
    = is a register (a special one called the "expression register"). To look up help for registers you precede them with @. So :h @=. For the specific context of expression register use in the substitution command there's :h sub-replace-expression aka :h s:\=.
    – B Layer
    Commented Mar 8, 2019 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.