3 ms·
This is one of many ways of doing this in Vim: you pick the way depending upon the task and what you prefer. Personally I would have used macros in this situati
by oniony 4y ago
This is one of many ways of doing this in Vim: you pick the way depending upon the task and what you prefer. Personally I would have used macros in this situation. Recorded my commands and replayed them across the resultant lines. It's actually interesting to see another Vimn user's approach.
Whilst what you're saying is correct about being able to do these things on your IDE/editor, one of the strengths of Vim comes from being able to program edits and then reuse them. I'm always stunned programmers don't naturally get drawn to Vim for this reason alone. And I actually use Vim bindings in my IDEs, giving me the tools from both worlds.
For example, if I made a macro that does all of the edits on a single line, I can replay that macro n times or – better still – play it only on lines that match a regular expression. You can basically describe the edits you want to make either by recording you making them (macro), or – like on this video – by hand constructing them. Either way you can then apply them like a distinct action (procedure) however you want.
Example: `:g/blah/s/a/b/g` will search (g) for all lines matching "blah" then substitute (s) "a" with "b" for all occurrences (g). Similarly `:g/bl.*ah/norm @a` will play my macro in register `a` across all the lines that match the regular expression `bl.*ah`.