Which depending on how you consider the novel and cut lines from the original script would be as Captain of Excelsior.
I'm trying to only go by what is on the screen. Even excluding the cut line about commanding Excelsior, Kirk does say he is glad to have him at the helm for three weeks. This suggests he is no longer part of the Enterprises regular crew and is only there on temporary basis. Which makes it very likely he has a pending assignment elsewhere. We don't know the nature of the assignment -- it need not be commanding the Excelsior, but something was happening after those three weeks. Of course, he could have also gave his resignation and that's when his service was ending. Either way, it's the same difference. Sulu was out of the picture for the new command crew.
What is more interesting is that if we accept that they were training a new crew for the Enterprise, how did Kirk get to the position he is at now? Prevailing theory seems to be that he had become an instructor / administrator at the Academy as he felt "too old" and it was time to pass on his experience to younger upcomming officers. This makes the goal seem more focused -- train and prepare a new crew for the Enterprise. Why would Kirk do this? He doesn't seem like he was poised to command again (until the Khan incident). Perhaps in the beginning the thinking was he would resume command, but as he went through the process he began changing his mind, feeling too old and removed from the younger generation.
McCoy's lecture to Kirk seems to be very late timing, unless we assume that this change of attitude was a subtle one, gradually developing over time and only now was coming to a crisis point. Unlike TMP, there appears to be no one groomed for succession like Decker was (pre V'Ger), unless we consider Spock.
Spock is a little harder to explain. On paper, he is clearly the captain. Starfleet promoted him from Commander (or from Lt. Commander depending on which source you go by) to Captain. This is a sign that he has value to Starfleet. If Enterprise is a ship being prepped for active duty, what is his role? Will he be her commander? Or is he more of a temporary captain like Styles, just running her crew through trials? If we believe Spock, he was just there for the teaching. But Vulcans do lie. And he was responding to a friend in need (no...put away the slash fiction).
Letting the reactions of Spock and McCoy inform us, it seems like Kirk began quietly orchestrating this succession of command to Spock without conversing with him. Something inside him told him he was done and that he was holding back Spock. So without soliciting the thoughts or wishes of his friend, he began positioning Spock to succeed him.
Of course, this is now VERY subjective and based on a lot of assumptions. In drama, characters voice issues at a point in the story the Audience needs the information, which is often not when they would naturally occur in real life.
Sorry to derail the thread, this went on longer than I had expected it to.