Three years in the same flat, and the sentence that reports it can go wrong in two places at once. Ich habe hier für drei Jahre gewohnt puts the years behind you in the tense and again in the preposition, though you have not moved out. Both came out of the English sentence you were translating, “I have lived here for three years”, which carries the same fact in a perfect tense and one small word. The second attempt usually rescues the tense and loses the preposition instead: ich wohne hier vor drei Jahren, in the present now, and counting backwards away from it.
Three German words share this job, and they are not three styles of saying one thing. Seit takes a beginning, either a point or a length, and says that what began is still going on. German then keeps the verb in the present where English reaches for the present perfect, for as long as the sentence is standing in the moment you are speaking: ich wohne seit drei Jahren hier, ich lerne seit September Deutsch. Vor counts backwards to something that is over, and its sentence goes into a past tense: vor drei Jahren bin ich hierher gezogen. Für measures a stretch with both ends fixed, taken as one span rather than as something still running: ich fahre für zwei Wochen nach Rom.
So the information English keeps in the verb, German keeps in the preposition. That is the part that makes ich wohne seit drei Jahren hier feel wrong to write: it looks like a present tense doing a past tense’s work, and it is not. It is a present tense saying that the thing is present, with seit supplying the three years. Ich habe hier drei Jahre gewohnt is also good German, and it is about a flat you have left.
The cases are worth stating, because a later post leans on them. Seit takes the dative, and so does vor in these time sentences, which is where the -n in seit zwei Jahren and vor zwei Jahren comes from: a dative plural adds an -n to the noun itself, unless its plural already ends in -n or in -s (den Frauen, den Autos). Für takes the accusative, which is invisible in für zwei Wochen and audible in für einen Monat.
Ich wohne seit drei Jahren hier.
Vor drei Jahren bin ich hierher gezogen.
Ich lerne seit September Deutsch.
Ich fahre für zwei Wochen nach Rom.
Seit dem Umzug sehen wir uns selten.
Seit dem Umzug has a twin, and it is where vor stops counting backwards. In front of a length of time, vor counts backwards: vor drei Jahren, three years ago. In front of an event, it means “before”: vor dem Umzug, before the move. So seit dem Umzug and vor dem Umzug stand on the two sides of the same afternoon, with nothing irregular happening in either.
The edge that trips people up
The present tense goes with seit as long as the sentence is anchored in the moment you are speaking, and that condition is the whole of the rule. Move the frame into the past and seit keeps its meaning exactly while the verb travels with the frame: er arbeitete dort seit 1990 says that in the year the story is set, he had already been there since 1990. Nothing about seit has changed. What changed is where “now” is.
Damals arbeitete er seit zehn Jahren dort.
The second edge is a spare form. A duration can sit in the sentence as a bare accusative with no preposition at all, and it says what für says: ich war zwei Wochen in Rom and ich war für zwei Wochen in Rom both exist. If you leave für out of a sentence like that one, you have not made a mistake.
Ich war zwei Wochen in Rom.
One more thing about vor, so that it does not ambush you later: the same word is a preposition of place, and there it takes the dative for a position and the accusative for a movement (vor dem Haus, vor das Haus). That is a different job, set out in the post on in den and in dem. German has one word for both, and that is all there is to it.
How to hear it
One question settles it, and it comes before the sentence does: is this still true as you speak? If it is, you want seit, and the verb stays in the present, whatever the English was doing. If it is over, you want vor and a past tense, which means choosing between bin and habe, and that choice has a post of its own. If the sentence gives the whole span rather than a beginning that still holds or a point behind you, you want für.
Italian divides this same job between da and per, and keeps half of the answer in the tense as German does, so if you have met that pair the shape here is already familiar: one preposition for what is still running, another for what is being handed over as complete.
Two of these words point from a single moment in opposite directions. Seit faces forward, from a beginning in the past to the sentence you are speaking, and keeps that sentence in the present. Vor faces back, from the sentence to a point that is closed, and puts it in the past. The number between them is often the same number: seit drei Jahren and vor drei Jahren can describe one span of three years from its two ends. What you are choosing is never the length. It is which end of it you are standing on.