3 ms·
My favorite use of macros is as a sort of progressive global search and replace on steroids. I have @q bound to Space, so I can record a macro with qq, then hi
by dasil003 10y ago
My favorite use of macros is as a sort of progressive global search and replace on steroids. I have @q bound to Space, so I can record a macro with qq, then hit space to repeat. Since the macro is just a list of commands in a register I can copy it out and edit it to tweak it, once I'm happy with it over a few lines I can make it recursive by adding @q to the end of it.
Compared to regex search and replace this is much more malleable, interactive, and ultimately powerful.
- fiddlerwoaroof 10y agoIt's worth remembering that . (i.e. dot) repeats the last edit command. vim-repeat ( https://github.com/tpope/vim-repeat https://github.com/tpope/vim-repeat ) makes this even better. Although, there are still several situations where macros are better, especially things that involve several motions and edits. (I tend to use qw because w is more convenient to hit after @). Also, it's occasionally useful to remember that you can use the double quote character " to paste a macro, edit it and then update it. i.e. ( "ep .... edit ... ^"ed$ )
- fiddlerwoaroof 10y agoAlso, vim-surround is one of those things that, once you've used it for a while, it's impossible to think of editing text without it: https://github.com/tpope/vim-surround https://github.com/tpope/vim-surround
- dasil003 10y agoAny vim user can profit from visiting https://github.com/tpope?q=vim&tab=repositories https://github.com/tpope?q=vim&tab=repositories and trying any one that looks vaguely interesting.
- mkingston 10y agoSomewhere between the default and your binding: @@ repeats the last macro. So you can record your macro, go to your search text, @q, n, then for all subsequent matches @@.