There is an opinion that one visiting Eretz Yisrael from the Diaspora is considered to be a resident of Eretz Yisrael for the duration of his stay (Ḥakham Tzvi §167). However, most poskim rule that since he lives abroad, he is considered a Diaspora resident even while visiting Eretz Yisrael. This is the opinion followed in practice (Birkei Yosef 496:7; MB ad loc. 13).
However, if an additional uncertainty arises – for example, if he expects to remain in Eretz Yisrael for an extended period of time, plans to make aliya, or has children living in Eretz Yisrael – then we combine this uncertainty with two other factors. First is the opinion above that everyone who is in Eretz Yisrael for Yom Tov should keep one day. Second is that, in recent times, there are increased chances that a Jew visiting Eretz Yisrael will decide to relocate there permanently. Combining these three factors, we instruct such a person to follow the practice of those who live in Eretz Yisrael.
Therefore, one who comes to Eretz Yisrael for an entire academic year is considered a resident of Eretz Yisrael, even if he has definite plans to return to the Diaspora, his parents live there, and he goes to visit them mid-year. His extended stay in Eretz Yisrael renders him a resident of Eretz Yisrael for the duration of his stay. Additionally, there is always the chance that he will decide to make aliya, given that there is a Torah commandment to live in Eretz Yisrael.
However, if one comes for a shorter visit, even up to half a year, and plans to go back to the Diaspora, he is considered a Diaspora resident. If he visits repeatedly, then once his visits cumulatively add up to a year, he is something of a local, and there is a certain chance that he will make aliya. Accordingly, when he is in Eretz Yisrael for Yom Tov, he may celebrate the way that residents of Eretz Yisrael do and keep one day.
If one is visiting Eretz Yisrael, even for a short time, but is planning to make aliya as soon as he can, then even if he will not be able to bring his plans to fruition for a number of years, his status while visiting is that of a resident of Eretz Yisrael.
If one visiting has children or parents already living in Eretz Yisrael, he is considered a resident of Eretz Yisrael while visiting. Even if he does not intend to make aliya, nevertheless he has deep family ties to Eretz Yisrael, so there is always a chance that he will make aliya.
If one buys an apartment in Eretz Yisrael and lives there during his visits, he is considered a resident of Eretz Yisrael while there.
If one emigrated from Eretz Yisrael, even if he has been living in the Diaspora for decades, since he lived in Eretz Yisrael for a long time, then as long as there is a chance that he will return to Eretz Yisrael, he should behave like a resident of Eretz Yisrael while visiting.
In all the above cases, since the person has not yet made aliya, while he is in the Diaspora he must keep two days of Yom Tov.
At first glance, it would seem that according to the general rules of deciding halakha, we should rule in accordance with Ḥakham Tzvi. After all, Yom Tov Sheni is rabbinic, and the principle is that we are lenient when there is uncertainty concerning a rabbinic law or concerning the recitation of berakhot. Nevertheless, we are stringent about Yom Tov Sheni and we add berakhot because the prevailing custom of Diaspora residents visiting Eretz Yisrael has been to keep Yom Tov Sheni when visiting Eretz Yisrael, and where there is an established custom, we do not apply the principle about being lenient about berakhot in a case of uncertainty.
However, when there is an additional uncertainty, it is possible that even those who are stringent would agree that one should act like a resident of Eretz Yisrael. For example, Ḥida attests that rabbis of Eretz Yisrael ruled that when students from abroad come to study in yeshiva and could conceivably make aliya, they are to be considered residents of Eretz Yisrael while there (Ḥayim Sha’al 1:55). This is despite the fact that Ḥida is among those who obligate visitors to keep a second day of Yom Tov when in Eretz Yisrael. It may be that most poskim would maintain that one must keep two days even when there is an additional doubt (as Igrot Moshe states in OḤ 3:74). Nevertheless, in such a case there is no long-standing custom that obligates us, so we can revert to the principle of leniency in cases of uncertainty concerning a rabbinic law. Accordingly, as long as there is an additional uncertainty, we do not obligate visitors to keep Yom Tov Sheni; even if they do so, they certainly should not recite the berakhot on the mitzvot of Yom Tov.
Another important factor has come into play in recent times. The Jewish nation has begun to return to its land, which is flourishing, and it is easier than ever to make aliya. (See MB 496:12, which cites poskim as saying that one of the primary considerations in applying the law of Yom Tov Sheni is the likelihood that a person will decide to remain in the place he is visiting.) Therefore, I wrote above that one who intends to make aliya has a serious relationship with Eretz Yisrael and may act like a local starting from his first visit. This is the case even if he does not know when he will manage to make his dream of aliya come true, and it may well take a number of years.
Significantly, it is possible for a person to have a dual status, such that he keeps one day when in Eretz Yisrael and two days when abroad. Thus, Maharit Tzahalon §52 writes that if one lives a year in Israel and then a year abroad, he has the status of a resident of Eretz Yisrael while he is in Eretz Yisrael and the status of a Diaspora resident while he is abroad. Aseh Lekha Rav, vol. 7, Teshuvot Ketzarot §33 rules this way as well.
Therefore, if one is simply visiting Eretz Yisrael, he observes two days of Yom Tov. But if he has come to study for a year, since he will be in Eretz Yisrael for an extended period of time, he is considered a resident to a certain degree. This is what R. Mordechai Eliyahu z”l ruled for students who come to learn in Eretz Yisrael. He said that while in Eretz Yisrael they should follow the local practice, and when they want to leave they should ask for a ruling as to whether leaving Eretz Yisrael is permissible for them. His opinion is based on the citation of Ḥida above. This is also what R. Goren writes in Teḥumin 24, p. 333.
It would seem that one whose cumulative time in Eretz Yisrael adds up to a year is also considered somewhat of a resident, and there is always a certain possibility that he will make aliya. Therefore, he should observe one day of Yom Tov. If one has parents or children who have made aliya, or if he bought a vacation apartment in Eretz Yisrael, he should behave as a resident of Eretz Yisrael while in the country, even if his cumulative visits do not yet add up to a year.