In Star Trek the motion Picture, it is established that Kirk is a rear admiral. However, he is addressed as Captain on the enterprise. Was this done because the heads of all vessels are traditionally addressed as captain?
At the start of the movie, Kirk's rank insignia is a gold leaf, showing he's an Admiral. When the Enterprise is underway, he's in a new uniform with the three strips on the sleeve cuff, a solid strip on the top and botton, with the middle strip interrupted. This is the Starfleet insignia for the rank of Captain.
At that point former Captain Decker has two solid stripes on his uniform, showing the rank of Commander. This is emphasized when Lt. Ilia first sees him and is puzzled and asks, "Commander Decker?"
So Kirk is a Captain by rank, as well as by title as the captain of the vessel.
It may or may not be worth noting that earlier, Decker has two stripes on his more formal uniform (I don't know if that was a dress uniform or not). It's also possible the shoulder insignia might differ from the sleeve insignia.
In the book, written by Gene Roddenberry, there's also a few lines that weren't in the movie in the scene in Engineering where Kirk tells Decker he's relieved of command. Kirk says:
You'll stay aboard as executive officer . . . a temporary grade reduction to commander.
This verifies that, for whatever reason, Decker could not remain in the rank of captain, which would make sense if Kirk's rank was reduced to Captain as well for the mission.
(Remember, the script for this came from the two hour pilot for Star Trek: Phase II and the original intent was to justify reuniting the old crew members and start a 2nd five year mission, where Kirk would be the captain and Decker would be the X.O. Even with a transfer to film, the idea of setting up another five year mission was still seeping through the final production of the movie.
In ST:The Motion Picture, Kirk's sleeve insignia was a broad stripe with a narrow stripe over it. That denotes a rear admiral in the US Navy. In the TV series, commodores wore the broad stripe on their sleeves and were flag officers.
He was temporarily reduced to captain in the movie and restored to flag rank afterward. He was permanently demoted to captain at the end of ST: The Voyage Home. Decker was reduced to commander and became the executive officer of the Enterprise.
In The Doomsday Machine, the commanding officer of the USS Constellation was Commodore Matt Decker which was unusual in that a flag officer was captain of a starship.
Until 1862, the US Navy had no flag ranks except for the honorary rank of commodore. Then Congress established the ranks of commodore and flag officer which was replaced by rear admiral. The rank of commodore was used from 1862 to 1899 when it was abolished. By the way, Dewey held the rank of commodore at the Battle of Manila Bay.
The rank of commodore was reestablished during World War ll as a temporary wartime rank in 1943. It was again reestablished in 1981 and was replaced by rear admiral (lower half) in 1985.