After ceiling or trim are painted and dry apply blue painters tape on the ceiling or trim in line with the wall. It is important that the paint is dry so the final step is successful.
Paint the ceiling or trim color (the color under the tape) on top of the tape and slightly onto the wall.
Let the paint dry. The tape doesn't create a perfect seal, especially on textured walls. This paint will seep into the openings under the tape which is okay as it's the same color under the tape.
Now, paint the wall color up into the corner and over the tape.
Before the wall color dries, start pulling off the tape. Pull away from both the ceiling and the wall. The same method also applies to trim.
Look at the clean and straight line. This clean of a line is virtually impossible using any other method. Good luck!