Hacker News new | past | comments | ask | show | jobs | submit login

>q to record a macro; @ to execute it again

Is using macros' really common? I haven't yet figured out in when and where to use macros during my workflow.




I do a lot of work on multiple rows/sections/blocks of similar data. My workflow usually goes like this...

1. Do the same thing 3 times, realize that I'll be done faster if I automate it. 2. qz to record a macro into buffer z. 3. Do the work, taking care to leave myself in a state where the next invocation of the macro will pick up right where I want it to. 4. q to finish recording. 5. :map <M-f12> @z to execute buffer z 6. Hit Alt-f12 over and over until I'm done.

Seems like a lot of steps, but it has saved me tons of time.

Of course, as the other commenter said, some folks don't use the feature. That's ok. There's room for all kinds :)


> 5. :map <M-f12> @z to execute buffer z 6. Hit Alt-f12 over and over until I'm done

Why map? @z and @@ till your are done? Or if you have this in your vimrc:

      vnoremap @@ :normal! @@<CR>
@z, visual select, and @@.


20@z repeats your macro 20times.


I use Vim on structured, tabular data quite a bit (think CSVs/TSVs/large HTML tables/etc.). Macros are handy for handling complex operations on rows like "skip the first two fields; delete this column; add this new column; make everything in this column uppercase; delete the rest". Just start recording, edit the first row and apply it to every other line when you're finished.


Macros are fabulous! Any time you're going to edit multiple lines in the same way, bam! For instance, you've got a create table script, and want to turn the column defs into some code or type definitions. For me, macros are quicker than getting a regex right.

Or perhaps you're cleaning up a file, and there's a few common changes. Pop each into a macro and go to town. The low friction aspect makes them more common than the name might sound.


Thank you for asking that.

I have been wondering the same thing for some time. I always hear how great macros are, but haven't actually found a real world use case in my work.

But I figured it was because I didn't know something.


Vim user of 18yrs here. I never use macros.

Everyone uses a slightly different subset of vim, in slightly different ways.

Don't worry about dogmas. Try everything out once, and keep what works for you!




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: