0

I wish to find an occurrence of a specific symbol inside a large string and prepend a space to that symbol.

NOTE: I also have occurrences in the file with the space already prepended to that symbol.

input

6890 4 2.025 12.219883 -80.86158
6891 1 36.45 11.314275-79.050365
6892 1 36.45 14.031098-79.955972
6893 1 2.025 13.12549-78.144757

output:

6890 4 2.025 12.219883 -80.86158
6891 1 36.45 11.314275 -79.050365
6892 1 36.45 14.031098 -79.955972
6893 1 2.025 13.12549 -78.144757

I first thought that the solution would have the following form

:%s/*-*/* -*/

This form does not account for the existing spaces

  • Vim uses regular expressions. See `:help pattern` for the full doc and [http://vimregex.com/](http://vimregex.com/) for a quick overview. – romainl Mar 24 '22 at 08:49

1 Answers1

0
:%s/\(\d\)-/\1 -/g

in entire file % substitute s/ a digit \d, (and capture it \(\d\)) followed by a minus -, and replace / with what was captured \1 followed by space and minus - with options / "all occurrences on the line" g

XPlatformer
  • 1,148
  • 8
  • 18