Judging by the ship sizes given and fighting ships fitting on the TV screen, most depicted combat in Star Trek happens at around 5 to 10 kilometers range. As an answer to another question states, Federation weapons range far exceed that distance. Other factions that use other weapons (disruptors, for example) seem to be not much less capable, yet also tend to close the distance within the show - for example, there are multiple instances of cloaked ships appearing at point-blank range, when they were not detected prior (i.e. the commanding officer chose to position their ships there, as opposed to somewhere farther). On the other hand, in TNG episode 4x12 "The Wounded", Phoenix is engaging a Cardassian ship at a very long range. In fact, it picks a tactic that seems much more reasonable from modern viewpoint - moves out of effective range of enemy weapons and then uses superior range of its own weapons to destroy the target. So the capability for effective long-range engagement does exist in Star Trek universe.
Of course, the out-of-universeout-of-universe reason for this is clear - ships firing at sensor blips invisible to naked eye is not as visually striking; but is the tendency of the Enterprise to fight at extremely close range ever explained in-universe?is the tendency of the Enterprise (or any Federation ship, for that matter) to fight at extremely close range as opposed to using the full range of their phasers and torpedoes ever explained in-universe?