No es una pregunta fácil... It's not an easy question
Cuando el verbo está en una forma personal (yo, tú, él...) se colocan delante y separados. When the verb is in a personal form, it have to be before the verb and separated.
"Yo lo necesito" "I need it"
"Ella se marchó" "she went away"
También cuando es imperativo negativo (se forma con el subjuntivo). We use it this way too when it's negative imperative (negative imperative is formed using subjunctive)
"¡No te vayas!" "Don't go!"
Cuando el verbo está en infinitivo, gerundio o imperativo (positivo), se coloca detrás formando una sola palabra. When the verb is in infinitive, gerund or imperative (positive), it have to be behind the verb forming a single word.
"Comerlo" "to eat it"
"Molestándome" "bothering me"
"¡Hazlo!" "Do it!"
Cuando is una perífrasis verbal (dos verbos), se puede poner delante del verbo auxiliar y separado, o detrás del principal (infinitivo o gerundio) formando con él una sola palabra. When it is a verbal periphrasis (two verbs), it can be before the auxiliary verb and separated or can be after the main verb (infinitive or gerund) forming just one word with him.
"Lo empezó a contar" "Empezó a contarlo" "He began to tell it"
Hay una excepción con las perífrasis, cuando son impersonales, debe ir siempre detrás del verbo principal formando una sola palabra. There is an exception with the periphrasis, when they are impersonal, it have to be after the main verb forming with him just one word.
"Hay que decírle esto" (I don't know how to traduce it using impersonal form in English)
Espero haberte ayudado. I hope that helps
Disculpa mi inglés, aún tengo mucho que aprender.
Sorry for my English, I still have to learn a lot.