3

I know there is a possibility to run a macro in multiple buffers using bufdo.

However, what I'm not aware, if there is somehow to use a "intercommunicated macro", e.g:

File 1:

foo
bar
bun

File 2:

{
}

Some pseudo macro: ggD(move to buffer 2)o "^R"": "^R"",(move back to buffer 1)

The result of such macro would be (after 3 iterations would be):

File 2:

{
  "bun": "bun",
  "bar": "bar",
  "foo": "foo",
}
2
  • 4
    Any reason you can't just put :b2 and :b1 in the macro?
    – Tumbler41
    Dec 15, 2016 at 18:52
  • Nooooo way ! Nooooo way. Damn, didn't even think about it ! Thanks a lot !
    – joaumg
    Dec 15, 2016 at 19:03

1 Answer 1

7

Just for completeness's sake (and so that this doesn't get bumped in six months by Community):

You can put a buffer command (:b) in macros. For your case:

qqggD:b#^Mo^R":b#^Mq

Where "#" is the number of the buffer you want to switch to, ^M is pressing <Enter>, and ^R is pressing <C-r>.

See :h buffer for more info.

Your Answer

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

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