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 '16 at 18:52
  • Nooooo way ! Nooooo way. Damn, didn't even think about it ! Thanks a lot !
    – joaumg
    Dec 15 '16 at 19:03
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, privacy policy and cookie policy

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