Need a little tip? No problem, I have a few too many spaces in this document. Of course, I inserted them on purpose, but sometimes we receive a document from the customer or we layout something ourselves with a lot of text. It can happen that two or even three spaces are inserted, and of course that shouldn't happen. That doesn't look good and it's very difficult for us to notice.
Step 1
I have shown the hidden characters under Font.
Step 2
We zoom into the document with Ctrl+Plus (+) and see that every dot is a space. In some places there are even two, which of course should not be the case.
Step 3
We could now go through the whole document line by line, but that would make us crazy. It would therefore be good if we could correct this automatically, i.e. replace several spaces with one.
With search/replace we can search for: Spaces Spaces and Change to: Spaces to remove all superfluous spaces.
Step 4
That would work, but the problem is of course that we have to go through every combination. That means one space, two, three, four, five, six, seven, eight. That doesn't have to be the case and it takes forever. So it would be better if it worked faster. Here are three spaces, for example.
Step 5
We wouldn't have removed the three now with search/replace, as we were only looking for two spaces. There is a GREP function for this problem. It is a bit complicated, but nevertheless it is very effective. Here, for example, we can say that we want to replace all spaces with one space.
The (\h) simply ensures that the horizontal spaces are searched for and then replaced with a space $1. The {2,} means that we want to search for one and more spaces that occur. So not just one space, but also two, three, four, ...
Step 6
It's a bit complicated, but we'll just accept it for now. As I said, I have deliberately inserted two, three and more spaces in some places in the document. Under Search we can choose where we want to search. We go to Document and click on Change all.
Step 7
As we can see, it has now had five hits and made five replacements. We click on OK and ...
Step 8
... we see that all superfluous spaces have been removed. Isn't that great?
Just remember, (\h){2,} change to $1. Here we can also just enter a space instead of $1, that would work too.
I think this is quite an interesting tip and will save some of you a lot of work.