Reputation: 308
I have a text document that has blank lines and lines that start with capitalized months.
I want to add "- " to the beginning of each non-blank line.
Tried this:
1,$s/^[A-Z]/- /
and it removes the first letter of the month (e.g. "- une" when it should be "- June") How can I add that letter back? Or is there a "better" way of doing this for a large document where I need to keep the blank lines untouched.
Upvotes: 1
Views: 722
Reputation: 8905
You have an answer that would either add the matched text back in, or avoid matching the text altogether during the substitution. Another method is to specify the match as zero-width, or set the ending of the match, so that the text is matched but not replaced:
%s/^[A-Z]\@=/- /
or
%s/^\ze[A-Z]/- /
See :help zero-width
, :help /\@=
, :help /\ze
.
Upvotes: 2
Reputation: 195039
try this, it should give what you want
%s/^[A-Z]/- &/
or use :g
:
:g/^[A-Z]/s/^/- /
Upvotes: 4