You can actually do this in two passes, one to handle numbers at the end of the line and one to handle numbers followed by a space:
:g/\([0-9]\) /s//\1.0 /g
The first simply finds a digit at the end of the line and replaces it with that digit and an additional
It uses a capture group
() to actually store the character that satisfied the search, and a reference
\1 to use that stored character in the replacement text.
The second one is very similar but with the following changes.
- It finds a digit followed by a space, rather than at the end of a line.
- It incorporates the space into the replacement string.
- It does it multiple times per line to change all integers, not necessary in the first case since there is only one end of line per line.
The result of running those two commands is, as requested:
1.0 alpha plural 1.0 0.0
3.0 1.0 4.0 1.0 5.0 9.0 2.0 6.0 5.0 3.0 5.0 8.0 9.0
2.0 7.0 1.0 8.0 2.0 8.0 1.0 8.0 2.0 8.0 4.0 5.0 9.0
42.0 972.0 insert point here
16.0 7.0 88.0
Now be aware that you can actually do this with the
s command rather than
g, I prefer the latter since you don't have to specify lines and it allows you to carry out much more powerful actions (the
s part of the
g command can be replaced with other more powerful commands, rather than just substitute).
If you don't want to use
g for some reason, you can do this instead:
:1,$s/\([0-9]\) /\1.0 /g