You can also omit the “with” and split the verb, but the meaning is different: “Ann went with David to keep him company.” This means that her purpose was to provide companionship to David (maybe they’re friends, David has to go somewhere and Ann goes with him so he won’t be alone).
“To keep company with”, on the other hand, simply means to associate with or spend time with people. The people you “keep company with” generally reflect on your personality. As we say, “birds of a feather flock together” or in Spanish “dime con quién andas y te diré quien eres” (tell me who you spend time with and I’ll tell you who you are). (I’m sure there’s an equivalent in your language.)