3 ms·
Two 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. Alt
by Xurinos 16y ago
Two 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> After the f(, you probably want h to move the cursor left onto the space before the (. Or just use t( to automatically move to the preceding space. ;) The best part about Vim is that you can ask 50 people about shotcuts and get 50 distinct answers, and each person can learn something new from each other. :)
- Xurinos 16y agoGood catch! So true. I forgot about this point, a concept I do not see a lot of in emacs: vim has a number of similar functions that differ purely by where the cursor ends up. The f vs t is one such distinction. Another is navigation of words by first letter or last letter (w vs e). Not often mentioned is the variations of block highlighting, where I can quickly (two or three letters) highlight my block and choose whether or not to include the beginning and end of block. For example, when I am in the middle of a sexp, vi( highlights everything inside the parentheses, and va( includes the parentheses. For {}s, just use vi{ and va{. And there are more options like these for saving keystrokes that, thanks to generally consistent policies, are the same for multiple commands -- cw (change the next word), dw (delete the next word), vw (highlight the next word), etc.