I have a macro that looks like:

:reg a
Type Name Content
  c  "a   /^where^MkV%yGo^M-- Some typing...:^[pVG:!/tmp/t.sh^M 

It works fine from any starting position in the file when I replay it with @a but attempting to execute it with :bufdo normal @a seems to just enter visual mode randomly and then stop. Trying :bufdo execute "normal @a" seems to be half working and half broken (a bunch of random bits of the file get pasted as well).

How can I reliably run an arbitrary macro over a set of files? How can I debug this, and what might be going wrong?

  • 1
    I managed to reproduce something similar to what you described if the line below the one starting with where starts with a bracket (such as {) that is unmatched (by a } in that case.) In that situation, the % command seems to fail and interrupt the macro and that leaves it in the visual line that was started just before that command. Do you think it's possible that that's what's causing the issue for you? In the buffer that this is failing, if you execute it normally with @a at the top, do you see the same behavior? Can you share a snippet of that buffer?
    – filbranden
    Oct 27, 2021 at 17:20
  • I had a nearly identical experience using neovim, where the macro would execute correctly when run in a single buffer, but would enter visual mode when run using bufdo. I ran neovim with the --noplugin flag and it worked perfectly, so it appears that one of my plugins was affecting the execution.
    – bart
    Mar 30, 2022 at 20:53


Your Answer

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

Browse other questions tagged or ask your own question.