I thought it should be “Je viens du acheter”. Is it because “acheter” has a vowel at the beginning?
De le becomes du only when le is an article, meaning "the". In this case le is a pronoun, meaning "it" (the book).
This sentence contains the particle de (part of the verb venir de) followed by the personal pronoun l' followed by the verb acheter. The usual form of this pronoun is le when referring to a masculine noun, and la when referring to a feminine noun. However, when the article is followed by a word that begins with a vowel, the pronoun is always elided to l'. The form l' exists for both genders.
This elision is also done when le or la is a definite article: le matin, la nuit, l'après-midi. It is also done when le or la is part of a partitive article: du pain, de la confiture, de l'eau.
Now let's suppose the verb didn't start with a vowel: “je viens de le vendre”. Why don't we say “je viens
du vendre”? There are two cases where de le contracts into du:
- When it is a partitive article (i.e. it means “some amount of”), as in du pain.
- When it the preposition de is introducing a noun group that begins with the definite article le, as in “je descend du train” (“je descend de la voiture”).
On the other hand, there is no contraction when de and le happen to be next to each other but they do not form a single unit. Here, de is part of the verbal compound venir de and le is a personal pronoun which forms a complement of this verb. There is no contraction when le is a pronoun: “je viens de le vendre”.
You are right about the vowel part, consider these two examples:
Du pain (instead of "de le pain")
De l'alcool ("alcool" is also masculine, yet "du alcool" is incorrect)
However, in your example the words "de" and "l'" are not linked at all, so you can't replace them by "du".
Consider these two examples:
Je viens de manger. (I just ate.)
Here "de" isn't quantitative but is used to introduce another subsentence, here "manger".
Je l'ai acheté. (I bought it.)
So they have no relation, and you can't say, for example:
Je viens du lire. (wrong)
But you need to say:
Je viens de le lire. (I just read it.)