3 ms·
Try :normal (:norm for short.) It can edit a set of lines given a certain set of vim commands. Sometimes simpler to reason with than regexes. E.g., if you want
by deathanatos 4y ago
Try :normal (:norm for short.) It can edit a set of lines given a certain set of vim commands. Sometimes simpler to reason with than regexes.
E.g., if you want to turn,
* a
* b
* c
into,
"a",
"b",
"c",
V, highlight the lines, :norm 2xi"^[A", — 2x to remove the star+space, i" to insert the quote — now we need to get out of insert mode, so that's tricky: Type ^V ESC there for verbatim ESC (I've rendered that in the command as vim will, ^[, but it will be colored to denote that it's a real ESC character) — then A", (append a quote and a comma).
You could do it with a regex, but I just find it far more natural to list the commands: my brain is already imaging it that way: remove the bullet, add the quotes and the comma.
Good for-loop for "do this to each line". Sometimes takes a bit of back & forth to construct the command, or sometimes it's just easier to do multiple :norm's. One of the best additions to my repertoire in years.