Fork me on GitHub
#spacemacs
<
2019-06-26
>
practicalli-johnny11:06:17

I finally got around to learning how to record an use keyboard macros in Spacemacs, specifically using Evil. Its really simple, q and a name to record, @ and a name to use. I'll add this to the book soon... https://github.com/practicalli/spacemacs-gitbook/issues/11 Anyone use a different approach with keyboard macros in Spacemacs?

Chris O’Donnell11:06:46

You can also do @ @ to execute the previous macro again; I do that pretty often.

❤️ 4
practicalli-johnny12:06:29

Thanks, that is really useful. I was wondering if such a thing was possible, as using . to repeat the macro didnt work

jeff.terrell12:06:15

And don't forget prefixing @@ with a number. I often have a macro that processes a line in some way. Then I'll either calculate how many lines remain and do them all in one go or else do a page full at a time (`50@@`).

lispyclouds13:06:53

relative line numbers save from calculating the lines too! 😄 and can do it in smaller, precise blocks

jeff.terrell12:06:45

This is exactly how macros in vim work, by the way, so this is another thing that evil-mode is faithful about.

❤️ 4
jeff.terrell12:06:53

However, I have noticed that macros are more robust and reliable in vim than emacs. I can't remember what I was doing, but a couple of times I've noticed that something that would work as a macro in vim doesn't work in emacs. It may have had to do with switching buffers. (Sometimes I had a macro in vim that would process a file in some way then switch to the next one.)

jeff.terrell12:06:50

One more fun note: you can create macros without q. All q does is record keystrokes into a register. If you typed out your keystrokes, including escaping control characters (`C-v` in vim, C-q in emacs), you can just yank the text to a register with e.g. "ay$ then execute it as a macro with @a. I do this sometimes to debug a long macro that wasn't quite right. Paste from the register, tweak the command string, then yank back to that register.

4
practicalli-johnny12:06:55

this is great, thanks. I will definitely be using keyboard macros more now.

metal 4
spacemacs 4
ag20:06:10

oh, macros can be totally mind blowing, did you know that you can also edit them? So you like record a macro, then run M-x edit-last-kbd-macro

👍 16