This might be a silly question.
Let's say I change jobs and country of residence-always within the European Union-every 3 years, purchasing monthly the same ETF through a local broker on each country (A, B, C, and D). This goes on for 12 years, after which I decide to take a sabbatical, move to a different European country (E), and start selling shares of the ETF to cover my expenses.
All five countries have different capital gains taxes. Which tax legislation applies? Which capital gains tax rate is applicable to the shares I sell?
In case that the applicable tax legislation is that of the country from which the shares were purchased (i.e. A, B, C, or D): if I had those shares in some sort of tax wrapper accounts (like UK's ISAs, or France's PEAs), would I still benefit from them?