Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Or, you could have hit qt, recorded your commands for the first change, and then replicated it for every other line with a simple @t, instead of redoing all the changes each time.

You don't have to learn command. You simply need to know how to edit with VIM.

And multi cursors only work for tabular data. The macro recordings can work for the entire document where you call a macro on a word/regex you searched for, for example.



I always find it strange that people recommend a different letter for the register when recommending macros. Why not just use `qq` and `@q` (with the added advantage that clearing the register is `qqq`) ?


The reason I don’t use q is it’s far too easy for me to accidentally hit a 3rd q when I didn’t intend to and not even realize it.

This was a bigger problem when Apple decided to go with those butterfly keys.


> multi cursors only work for tabular data

There are several plugins which allow for more complex use of multiple cursors.

* https://github.com/mg979/vim-visual-multi

* https://github.com/terryma/vim-multiple-cursors


I did record it with qd...q and repeated it with @d @@


Visual select and normal@t (assuming you saved it in t) is a good way to do it once for every line.


Nope, you can do find > select all to get multiple selections and edit those simultaneously.


This can be done in (neo)vim too, and with a bit better precision and less typing.

:g/<regex>/<command>

is the general form for [g]rabbing lines that match a regex and applying a command over them. You can also chain the command:

:g/<regex1>/g/<regex2>/<command>

I'll admit this isn't exactly something you intuit as easily as a drop-down menu, but (neo)vim does have tools for all these things out of the box.


Huh, somehow it’s never occurred to me to get binary logic by chaining :g and :v in this way—I’ve always done things in more complicated ways to make up for the lack.


Multiple cursors is for quick small editing tasks where you don't bother with a macro.


You probably are familiar, but for some newer folks: I almost always add a "go to beginning of next line" as the end of the macro so that I can e.g. 10@t to repeat it 10 times. Makes it much quicker than @t on each line once you have more than a few.




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

Search: