Both 给 and 为 can mean "for." Both can be used with verbs to express an action done for anyone.
So how can I distinguish? Please make it clear.
Thank you so much.
My feeling is:
That 给 is for doing something ''for'' someone.
I will buy it for you. 我给你买。
You will do the verb for someone else.
And 为 is more abstract
I am sad for you. 我为你伤心。
I'm not native but I don't think you could say:
我为你买东西。 X
我给你伤心。 X
If you do something 'for someone's sake' or 'on behalf of someone', you can use 给
[给 + noun] = [for + noun (for noun's sake)] e.g. 给我买东西 (buy thing for me = buy thing for my sake)
[给 + noun] = [for + noun (on behalf of noun)] e.g. 给我重重打 (severely beat someone for me = beat someone on my behalf). In this case, 给 is interchangeable with 替 (on behalf of)
If you do something 'for someone's sake', or 'because of someone' you can use 为
[为 + noun] = [for + noun (for noun's sake)] e.g. 为我买东西 (buy thing for me = buy thing for my sake)
[为 + noun] = [because + noun ] e.g. 为我而受苦 (suffering because of me). In this case, 为 is interchangeable with 因 (because of)