1

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.

2

Does that work for you?

:%s/^T0$/\=readfile('filename')/g

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? – BillThePlatypus Mar 8 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 Mar 8 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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