1

I recorded this macro to register a in Neovim by first pressing qa:

Macro

--- Registers ---
"a   f1F1i-^[la0^[j

Then I pressed q and my cursor was left in normal mode at the position marked by | (so that m is highlighted) in the below JavaScript snippet (on line 4).

JavaScript snippet

  timeout = setTimeout(function() {
    mw_panel.style.left="-10em";
    mw_head.style.left="-10em";
    content.style.left="1e|m";
    left_navigation.style.left="1em";
    footer.style.left="1em";
  }, 350);

Then I tried to apply the macro with @a but nothing happened. I tried the same in Vim and nothing happened. Though the macro will move the cursor to the 1 if I move it away before using it. Am I not understanding something about how Vim macros work?

1

Macros abort when they fail at some point. In your example, f1 fails since there is no 1 after the cursor. To solve it, you can set "a to, say, 0f1i-^[la0^[j.

| improve this answer | |
0

I would use sdp's suggestion 0f1i-^[la0^[j in a case like this, but my original macro could "directly" be made to work by absorbing the errors by the method described in this answer:

:try|exe "norm! f1"|endtry|try|exe "norm! F1"|endtry^Mi-^[la0^[j
| improve this answer | |

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.