One of the functions of the に particle is showing the purpose/goal of an action (動作・作用の目的を表す), ie "買いに行く", so you can replace 行く, but as Chocolate helpfully corrected me in the comments, the way you express this in Japanese changes depending on whether or not the verb expresses movement.
If it is a movement verb, such as 行く/来る/帰る, you use the 連用形{れんようけい} form/masu stem of the action or a noun that expresses an action + に + the movement verb.
Examples:
友達が遊びに来るんだ。
買いに行く。
映画を見に行く。
買い物に行きます。
If you are using any other verb except for that, you need to add の before に.
Examples:
ご飯を食べるのに使うお茶碗
えんぴつは字を書くのに使います。