Reputation: 63
Regex Question: how do I replace a single space with a newline in VI.
Upvotes: 5
Views: 1314
Reputation: 4011
\([^ ]\|^\)\([^ ]\|$\)
will find lone spaces only if that's what you need.
Upvotes: 0
Reputation: 5589
:%s/ /^V^M/g
note: hit ctrl-v, ctrl-m.
edit: if you really mean all single spaces, meaning spaces not followed by another space, use this:
:%s/ \{1\}/^V^M/g
and if you really meant just the first single space in the document, use this:
:%s/ /^V^M/
Upvotes: 8
Reputation: 11284
Just do the following in command mode:
:%s/ /\r/gic
gic in the end means:
- g: replace all occurrences in the same line (not just the first).
- i: case insensitive (not really helpful here but good to know).
- c: prompt for confirmation (nice to have to avoid you having to do immediate undo if it goes wrong :) ).
Upvotes: 5