0

I have a data that looks like

:stuff  #object[java.time.Instant 0x4ddb2473 "2016-03-04T00:00:00Z"],
:stuff2 #object[java.time.Instant 0x62bc763e "2046-04-01T00:00:00Z"],

I want to change it to

:stuff  (jt/instant "2016-03-04T00:00:00Z"),
:stuff2 (jt/instant "2046-04-01T00:00:00Z"),

I start the macro by pressing qt. I type a series of commands that correctly does this change. I save the macro with q. Then I press @t and it breaks.

This is the data after I call @t

:stuff let b:sexp_count = v:count | execute "normal! vvm`" | call sexp#move_to_nearest_bracket('o', 0) | if v:operator ==? "c" |   call <SNR>32_repeat_set(v:operator . "\<Plug>(sexp_move_to_prev_bracket)\<C-r>.\<C-Bslash>\<C-n>", b:sexp_count) | else |   call <SNR>32_repeat_set(v:operator . "\<Plug>(sexp_move_to_prev_bracket)", b:sexp_count) | endif
jt/instant],
:stuff2 (jt/instant "2046-04-01T00:00:00Z"),

Note that this is three lines. jt/instant], is moved to its own line.

This is what's stored in the t register

/#@<80>kb^Mct"(jt/instant^[^[f"df"F)i ^[^[pf]x^[^[

EDIT:

Sexp related plugins:

  • guns/vim-sexp
  • tpope/vim-sexp-mappings-for-regular-people
  • tpope/vim-repeat
  • tpope/vim-surround

Key presses:

/#<enter> ct" (jt/instant<esc> f"df" F)i<space><esc>p f]x F<space>x q

The whitespace are not key presses. I added them in to make it easier to understand by grouping logical chunks together. Ex: /#<enter> finds the line I want to change.

8
  • 2
    Which sexp plugin (if any) are you using? Can you also show what you typed while recording the macro?
    – D. Ben Knoble
    Sep 23 at 20:58
  • May or may not be related to the problem but why are there two Escape key presses (^[^[) everywhere one would expect just one? Are you hitting it twice or is it just being recorded that way?
    – B Layer
    Sep 24 at 9:54
  • @BLayer I'm hitting Escape twice. It's not needed for the macro, but I guess habit?
    – triplej
    Sep 24 at 14:34
  • Oh, okay. No harm, no foul, I guess. (Though you're wasting a keystroke and it's apt to cause confusion elsewhere as it did here...might be a good habit to break. :)
    – B Layer
    Sep 24 at 14:37
  • @D.BenKnoble I edited to show what I typed when recording the macro and the plugins.
    – triplej
    Sep 24 at 14:46
0

I can’t fix your macro, which relies on auto-insert behavior, but I can suggest a different approach:

  • /#<cr> move to line
  • dt[ds[ delete square brackets and stuff
  • dt" clean up the rest
  • ysa"b Surround the quotes in parens
  • 0f(ajt/instant <esc> insert the prefix (this can be simplified but I couldn’t predict the cursor position when executing in my head, so I was conservative).

Wrap in a macro, or use

:global/#/normal f#dt[ds[ysa"b0f(ajt/instant 

Note trailing space.

Note that surround also has ysa"<c-f> for surrounding with lisp style function calls, and it is repeatable, but not likely to play well with a macro or global command.

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.