Reputation: 5767
I want to add a minus sign "-" infront of the first word in a line on the editor VIM. The lines contains spaces for indentation. The indentation shall not be touched. E.g
list point 1
sub list point 2
and so on...
- list point 1
- sub list point 2
- and so on...
I can find the first word, but i struggle with replacing it in the correct way.
^\s*\w
in Vim
/^\s*\w
But in the replacement I always remove the complete found part....
:s/^\s*\w/- \w/
Which leads to
- ist point 1
- ub list point 2
- nd so on...
Upvotes: 1
Views: 242
Reputation: 196556
I'm late to the party but:
:%norm! I- <CR>
And another one with :s
:
:%s/^\s*/&- /
Upvotes: 2
Reputation: 195059
:normal cmd may help too:
:%norm! wi-
note that after -
there is a space.
Upvotes: 1
Reputation: 157992
An alternative to falsetrue
's answer: You can capture the first word character and print it out along with the leading -
:
%s/\(\w\)/- \1/
Upvotes: 1