〜に行くgo to do (something)
You go somewhere, or come, in order to do something. What you go to do comes first, with に: 見に行く is "go to see".
My younger sister went to see a movie with a friend.
I often go shopping with my family on weekends.
With a verb
Verb ます-stem + に + 行く/来る/帰る
ます comes off and に goes on: 見ます → 見に, 買います → 買いに, します → しに. The verb at the end is always one of going or coming.
With an activity noun
Activity noun + に + 行く/来る
買い物に行く, 散歩に行く. To ask what for: 何をしに.
Going to do something
The に part never changes. The verb at the end carries the tense and everything else: 行きたい, 行きませんか, 来てください.
Tomorrow, I am going to the bank to withdraw money.
Tanaka came to see the teacher.
先生に belongs to 会う. The second に is the one that says what for.
I went back home to get something I had forgotten.
Would you like to go and have lunch?
With an activity noun
A noun that names an activity takes に directly: 買い物 (shopping), 散歩 (a walk), 旅行 (a trip), 食事 (a meal).
On Sunday, I went to the park for a walk with the children.
Ones you'll hear every day
遊びに行く・来るgo out for fun; come over
Please come over to my place sometime.
Between adults 遊ぶ isn't "play". It is spending time together or going out.
飲みに行くgo for a drink
Would you like to go for a drink tonight?
迎えに行く・来るgo or come to pick someone up
I am going to the station to meet a friend.
駅に is where. 迎えに is what for.
取りに行く・来るgo or come to get something
I have come to pick up my package.
Where the place goes
The place takes に or へ, because it is where you go. It can stand before or after the thing you go to do.
My mother went to a shop near the station to buy a cake.
Not said: デパートで
(I am going shopping at the department store.)
デパートへ買い物に行きます.
It is always a real trip
English "I'm going to eat" can be a plan with no travel in it. 食べに行きます never is: you leave and go somewhere to eat.
I am going out to see a movie tonight.
You go to a movie theater.
I am going to watch a movie tonight.
A plan. You might not leave the sofa.
Only with going and coming
When the verb at the end is anything else, "in order to" is ために.
Not said: 日本語を
(I bought a book to study Japanese.)
日本語を勉強するために、本を買いました.
Close neighbours
にN5
After a place, に is where you end up. After a time or a person it is "at", "on" or "to".
Every morning, I go to the station.
ためにN4
"In order to" before any verb. It is for a goal you work toward, and sounds heavy for an errand.
I study Japanese every day in order to study abroad.
Check yourself
1"I went to the supermarket to buy milk."
スーパーへ
Choose an answer to see why.
2What does this mean?
姉は
Choose an answer to see why.
3Which sentence sounds natural?
Choose an answer to see why.
More detail
買い物に or 買い物しに?
With a する verb both are said, and they mean the same: 買い物に行く, 買い物しに行く.
More sentences
My friend came to study Japanese.
On weekends, I go to a nearby park to run.
I want to go to Hokkaido during summer vacation to take photographs.
What are you going to Kyoto to do?