"Der Lenker eines Fahrzeuges hat, sofern sich aus diesem Bundesgesetz nichts anderes ergibt, so weit rechts zu fahren, wie ihm dies unter Bedachtnahme auf die Leichtigkeit und Flüssigkeit des Verkehrs zumutbar und dies ohne Gefährdung, Behinderung oder Belästigung anderer Straßenbenützer, ohne eigene Gefährdung und ohne Beschädigung von Sachen möglich ist. [...]"which translates to "The driver of a vehicle must, if not stated otherwise, drive as far on the right as it is possible concerning ease and liquidity of traffic but without endangering, constraining or harassing other road users, without putting oneself in danger and without damaging things." Ok, I'm a bad translator, but well, I guess you get what it's about.
The thing is, most beginners mistake this regulation with "you have to drive as far right as possible to let cars pass easily". And that is really dangerous. Why? This is what I'm going to explain in this post. So I don't tell you, what distance you have to keep from the right edge or where you have to ride on a bike path. The thing is: You have to feel safe! Where would you ride if there was no other road user around? That's where you should be riding anytime, even if there are a hundred honking car drivers around you. Of course, the busier the road, the more careful you have to ride (shoulder check etc.), but it shouldn't change anything about your position. And, even more important, don't overestimate the lines that divide the bike lane from the rest of the road. I'm not telling you to ignore the traffic rules, but you should be able to tell when a bike lane is actually more dangerous for you than the rest of the road (e.g. if it is only half a meter wide and directly beside a line of parked cars).
I'm now going to make you feel unsafe in order that you can estimate the dangers on the road better - and to find a good position for yourself :-). Plus, if you are self-confident enough to take the space you need, also car drivers will respect that.
- Opening car doors: Whenever you pass a parked car, be aware that there might be somebody inside, driver or passenger, that wants to get out of the car the minute you pass by. And unfortunately, some people don't check if it's safe to open the door before they do so. And even if you manage to swerve around, there might just be another car overtaking you that can't.
- Empty parking spots: If you don't stay in your track, cars will overtake you and cut you off. Have you ever seen a car following wiggly lines when they want to drive straight on? Don't swerve in and out of the parking lane!
- Pedestrians: Some pedestrians don't look before they cross a road, especially when they "hear" that no car is around. If you can't observe the road edge well (e.g. because of parked cars, bushes, walls etc.), stay away from it.
- Tram rails: There are two options where you can ride - right of the right rail or in between. With rails it is even more difficult or dangerous to swerve, especially when they are wet. That's because it is not so easy to cross them, i.e. much easier to fall off.
- Manholes, potholes, speed bumps etc.: Well, they are not that dangerous, but certainly uncomfortable if you hit them.
- One-way and small streets: It mostly happens in one-way streets and on bike lanes that cars squeeze by letting hardly any space for you. If you don't feel safe in such a situation cause the road is not wide enough, don't allow it and ride in the middle of the lane. They might honk, but be aware that it's not your fault. In the end it's the width of their fat cars that prevents them from overtaking and not your small bike.
If you feel comfortable to undertake (that is overtake cars on the right that had to stop at a red light) you can do this with less distance because you're the only vehicle that is moving. But you should still be aware of the dangers above (maybe a passenger wants to get out of a standing car at the very moment).
A taxi half parked on the bike lane. Can you see whether somebody wants to get out? Maybe there is a child or dog behind the cab that wants to cross the road? Might that little bump cause trouble and do you have to reduce speed? Isn't that bike lane to small and too close to parked cars to ride safely? Well, a bike lane isn't safe just because it's a bike lane. You have ride safely yourself.
Tram lines: On the street in the left picture I cycle on the small concrete bit in between the right rail and the cobblestones or in the right half in between the rails. On the second street I definitely ride in between the rails.
There's a long list of situations and how to deal with them on "How to not get hit by cars". It also contains some tips about positioning on the road -- e.g. "ride further left" is mentioned in nearly every situation. Apart from that, the most important "tool" for a cyclist imho is a shoulder check. Never forget that.
Hm, I think I wrote quite a lot now, maybe too much. Was it helpful? Can you add something that's important to you?