4 ms·
"For example (and there are many), vim folks make their lives quickly easier by using (book)marks and macros; compare the key combos for these in vim to the one
by kroger 16y ago
"For example (and there are many), vim folks make their lives quickly easier by using (book)marks and macros; compare the key combos for these in vim to the ones in emacs, and you will see one reason why emacs editing is, by default, slower."
Could you provide a concrete example? I'm not trolling, I never used vi but I use emacs a lot and find emacs macros very useful and powerful.
- hazzen 16y agoVim 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.
- parbo 16y agoHow about F3<do stuff>F4?
- Xurinos 16y agoOnly one macro?
- delackner 16y agoAnyone? 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?
- angusgr 16y agoI 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.
- almost 16y agoParbo 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.
- dpritchett 16y agoLast week I forced myself to pull a bunch of names out of HTML for a dropdown listbox using a vim macro. I could've used a regular expression but I wanted to learn vim macros. Here's what I did. No guarantees that this is the right way to do it or that it's better than emacs. q0 (start recording a macro to store in buffer 0) df" (delete everything from cursor through the next quote character) f( (jump to the next open paren) d$ (delete everything from cursor to end of line) j (cursor down one line) 0 (skip to beginning of line) q (finish recording macro) 50@0 (execute macro 0 fifty times) That turned a bunch of lines that looked like <option value="My Full Name (domain\account)">My Full Name (domain/account)</option> into lines that just looked like My Full Name To reiterate, I typed q0df"f(d$j0q50@0 and my problem was solved with little thought.
- Xurinos 16y agoTwo helpful mods to your macro: (1) After the f(, you probably want h to move the cursor left onto the space before the (. (2) Instead of d$, just use D. Alternative for both those comments: Replace d$ with Dx More than one way to do it anyway... I would have spammed "qq" instead of "q0" to save finger space, but you might have already been using your q register for all I know. The other nice thing about vim macros is that since they are stored in vim registers, they can be accessed and manipulated. Make a one-keystroke mistake in your macro? Paste it to your buffer, edit it, and copy it back into the register. Now you can use it again. Example: "0p => df"f(d$j0q Modify to be df"f(Dxj0q and highlight and "0y For the readers, " accesses a register, y = yank, p = paste. Emacs defines "yank" the opposite way of vim: it means to yank from the clipboard and paste to your buffer. In vim, it means to yank it out of your buffer and put it into your clipboard (another register, as it happens, along with special registers that understand different levels of your OS's clipboards).
- dpritchett 16y agoThanks for the tips. I wrote my first vim macro last week so obviously there's a lot more for me to pick up!
- nuclear_eclipse 16y ago
- Xurinos 16y agoMark example: mm - the cursor position is now known as mark "m" `m - return us to the cursor position named "m"