Devarim12:28

שְׁמֹר וְשָׁמַעְתָּ אֵת כָּל־הַדְּבָרִים הָאֵלֶּה אֲשֶׁר אָנֹכִי מְצַוֶּךָּ לְמַעַן יִיטַב לְךָ וּלְבָנֶיךָ אַחֲרֶיךָ עַד־עוֹלָם כִּי תַעֲשֶׂה הַטּוֹב וְהַיָּשָׁר בְּעֵינֵי יְהוָה אֱלֹהֶיךָ׃

Keep and listen to all these words that I command you, so that it may go well with you and with your children after you for ever, when you do what is good and right in the eyes of the Eternal your Almighty.

Devarim 12:28

שְׁמֹר וְשָׁמַעְתָּ אֵת

Devarim / Deuteronomy 12:28 · Pshat

Devarim 12:28

שְׁמֹר וְשָׁמַעְתָּ אֵת כָּל־הַדְּבָרִים הָאֵלֶּה אֲשֶׁר אָנֹכִי מְצַוֶּךָּ לְמַעַן יִיטַב לְךָ וּלְבָנֶיךָ אַחֲרֶיךָ עַד־עוֹלָם כִּי תַעֲשֶׂה הַטּוֹב וְהַיָּשָׁר בְּעֵינֵי יְהוָה אֱלֹהֶיךָ׃

Keep and listen to all these words that I command you, so that it may go well with you and with your children after you for ever, when you do what is good and right in the eyes of the Eternal your Almighty.

Pshat פְּשָׁט

Good and right

Sometimes a person is right before God but hard on people. Or the reverse: pleasant to everyone, with a troubled conscience. The verse asks for both.

Rashi: "keep" is the learning you must keep inside yourself so as not to forget. Let a light commandment be as dear to you as a weighty one. "Good" is in the eyes of Heaven, "right" in the eyes of people. Haamek Davar: one who tangles a matter and tires the sages to untangle it is not good before the Eternal nor right before people. One who takes care in advance does what is good and right, and for this it will go well with him and his children.

How Rashi and Haamek Davar explain it

Rashi Keep

This is the learning (מִשְׁנָה) that you need to keep within you so that you do not forget, as it is said: "For it is pleasant if you keep them within you" (Mishlei / Proverbs 22:18). And if you have repeated it, you can hear and fulfil. Hence: whoever does not come to learning will not come to the deed.

Rashi All these words

So that a light commandment be as dear to you as a weighty one.

Rashi The good

In the eyes of Heaven.

Rashi And the right

In the eyes of people.

Haamek Davar So that it may go well with you and so on, when you do the good and the right

It is known that "the good and the right" means "in the eyes of the Almighty and people". So in the Gemara's discussion of the laws of the neighbouring landowner and of returning assessed property: they are derived from "and you shall do the right and the good". And see above (Devarim / Deuteronomy 6:18).

And it bears on our place like this. One who made a matter faulty and brings it to the sages to teach how to set it on the basis of the law, and wearies them with it, is not good before the Eternal nor right before people. But when he is careful in his words so as not to come to this, that is the good and the right, and by its merit it will go well with him and with his children.

Takeaway

Rashi reads the two verbs in order: "keep" (שְׁמֹר) — first learn and hold in memory, "and listen" (וְשָׁמַעְתָּ) — then fulfil. Learning comes before the deed.
The neighbouring landowner (בַּר מִצְרָא) is given the first right to buy a field for sale next to his land, though by law the seller is free (Bava Metzia 108a). The sages derive this from "and you shall do the right and the good in the eyes of the Eternal" (Devarim / Deuteronomy 6:18): acting rightly with one's fellow goes beyond the strict law.
Before our verse the Torah speaks of what is consecrated for the altar (Devarim / Deuteronomy 12:26–27). Haamek Davar explains: one who consecrates with unclear words and then goes to the sages to find out what he has done wearies them. Care with words is itself "the good and the right".