I have two code files open and I'm trying to write a macro for moving code from one file to the other. I start recording the macro in file A. After I enter all of the commands I need in file A, I switch into file B using gt. After I've switched, the commands that I run in file B are not included in the macro. If I try to end my recording with q while in file B, I instead initiate a new recording. When I go back to file A, my original macro is still recording. If I stop that recording and run the macro it only does the commands I entered in file A, but that does include the command to switch files.

If it helps, I'm using the vscodevim extension for vim emulation in Visual Studio Code

Is it possible for me to record commands across multiple files into a macro? If so, how?

  • It might be easier to write a function that runs norm commands than recording a macro. – James Feb 13 '19 at 16:53
  • @DJMcMayhem agreed, but im surprised that macro-recording doesn’t persist across tabs. Has OP tried with windows (splits) instead of tabs? – D. Ben Knoble Feb 13 '19 at 18:43
  • @D.BenKnoble I tried using splits, but the macro recording is still confined to the window where I start it. From what I've read, it seems like the commands in different files stay separate from each other because they are tied to the buffer that they are run in, so switching buffers switches out of the macro recording. I think the suggestion from @DJMcMayhem to use a function with norm commands is the best way to do what I need. – Rainbacon Feb 13 '19 at 19:00
  • 5
    @Rainbacon This must be a quirk of VSCode’s vim, because things work fine in terminal vim. – D. Ben Knoble Feb 13 '19 at 19:02

This bug has been documented on the VsCode/Vim repo. Bugs #5636 and #5123 both show that this is a current limitation in this extension.

As stated in the above comments, recording and replaying macros across different buffers (whether they be splits or tabs) work just fine in vim itself.


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.