To vote in a state, you must be a resident of that state. While attending school out of state does not terminate your legal residency in A, establishing residency in B does. If you want to vote in B, become a resident and register in B; if you want to remain a resident of A and vote in A, don't do that.
Establishing residency in B generally boils down to intending to reside in B for more than a temporary period. I suspect that most states do not have a universal definition of "resident", so for example in Washington, each agency has its criteria for residency. To register to vote, you have to be a legal resident and live at the address for 30 days (prior to the next election). One way to establish residency is getting a drivers license, which has a residency requirement that is satisfied by receiving state benefits (only available to residents), registering to vote (hmmm), getting, according to Licensing, or "Declaring residency for the purpose of obtaining a state license or tuition fees at resident rates", according to the actual law, in-state tuition, or get any state license at resident rates (we see a pattern here). The Department of Licensing also accepts utility bills with address (excluding cell phone, internet, or satellite), bank statements, and so on. This, BTW, is the most common path to establishing residency: take a bank statement or similar with street address to the license office. For hunting and fishing, you have to live in a permanent place of abode in the state for 90 days. There are a number of ways to show that: use a Washington address for federal taxes; run for public office or use a Washington address for some court papers; be a custodial parent of a child attending school in the state; register to vote, have a driver's license; register a vehicle in the state. The suicide law restricts the right to medical suicide to residents, proof of which includes (is not limited to) having a Washington driver's license (which is not the same as a state ID card), being registered to vote, or owning / leasing property in the state.
There is a social services definition, based on either living in Washington intending to continue for an indefinite period, or entering the state looking for a job with a job commitment and it explicitly says "A person does not need to live in the state for a specific period of time to be considered a resident". But for tuition purposes, you have to have moved to the state for reasons other than tuition, and you have to have been here at least a year. Ohio similarly has an agency-by-agency approach to "residency". If you exclude financial benefits and focus on drivers license or state ID and voter registration, you can probably make a reasonable guess as to the requirements. There is no official registration or form to fill out to become "a resident" (as far as I know, in any state), so the law will say what could constitute evidence that you are a resident. It may come down to "intending to reside for an indefinite period" in B.