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

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: