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

> Or typing only Q because you didn't hit the : and accidentally entering ex mode.

I'm not certain this is different (because I don't use either deliberately) but I'm forever hitting q (not even trying to quit) and entering some kind of macro recording mode.

I think the only reason I haven't yet disabled it like you suggest (after doing it for years now) is that... Well 'some kind of macro recording' does sound like it might be pretty useful if I bothered to learn to use it!



Macros are really nice, you can automate transforming several lines of text with them. The Vim plugin in Intellij supports them. Worth learning IMHO.


Indeed, I would not recommend disabling q unless you know what it does and tried it a few times.

For a quick demo, try it on this file:

    hello world!
    here's wolves
    what's up with the hackers?
Go to the first line and do:

    1. qq starts a macro named 'q'
    2. $vbgUj select last word on line, uppercase it, go down one line
    3. q to end macro recording
    4. @q run the macro
    4b. @@ repeats the last macro
    4c. 100@q runs the macro 100 times
When you want to do multi-line edits and the columns are not aligned (so block mode, Ctrl+V, doesn't work), this works wonders. You just record whatever you would do on every line plus whatever motions you use to go to the next occurrence, using things like "f|" (find the next pipe symbol) or "/example<Esc>n" (find the next instance of "example"), and then run the macro however many times. If you specify a number of times greater than the file is large, it will automatically stop at end of file, and you can also cancel if it takes too long (Ctrl+C) and undo what it did so far (u).

Alternatively, sed -i s/a/b/ my.txt is much much faster than macros, but macros can be more complex and are often easier to record (since you're just showing the computer what to do in a human way) than trying to regex the line.

I tried recording it for the lazy but asciinema is having issues (server error when uploading).




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

Search: