Hacker News new | ask | show | jobs
by hazzen 5796 days ago
Vim define a macro (stored in q because it is easiest, but to change the name replace the second q with any letter):

  qq<do stuff>q
Emacs define a macro:

  C-x ( <do stuff> C-x )
Vim do that macro again 40 times:

  40@q
Emacs do that macro again 40 times:

  C-u 40 C-x e
Naming a macro in Emacs (so you can have multiple) takes even more keystrokes and I'm not entirely sure on the incantation to repeat a macro from name - none of the help files seem to tell me how to do this, only to save it.
2 comments

Parbo already pointed out F3 and F4 for the first part. For the second part (repeat it 40 times) you could use:

    M-4 M-0 F4
Which is only 4 characters, the same as VIM.

Of course the F keys are a bit further to reach which can slow things down a bit. But it does leave it as not that great an example of the VIM being better. I'm sure there are better examples. Although I'm an Emacs user I've got learning VIM in more detail on my todo list.

How about F3<do stuff>F4?
Only one macro?
Anyone? I'd like to know the emacs way to save the expression into a register. Or is there a way to cycle through expressions that were previously repeated?
I think one way of doing what you suggested is

M-x name-last-kbd-macro

which will bind the last macro you defined into a named function for the rest of the session.