I often work with text files that have a variable number of spaces as word separators (word processors such as Word do this to distribute a fair amount of spaces due to the different size of letters in certain fonts, and they put this annoying space variable even when saving as plain text).
I would like to automate the process of replacing these sequences of spaces having a variable length with single spaces. I suspect that the regular expression can do this, but there are also spaces at the beginning of the paragraphs (usually four of them, but not always) that I would like to leave unchanged, so basically my regular expression should also not touch leading white spaces, and this adds to the complexity.
I am using vim, so a regex in the regex vim dialog would be very useful for me if that is doable.
My current move is as follows:
:%s/ \+/ /g
but it does not work correctly.
I am also thinking of writing a vim script that could parse text strings one by one, process each char string to char and skip spaces after the first, but I have the feeling of being excessive.
vim regex
jedi_coder Oct 05 2018-10-10T00: 00-10
source share