"Neither have I."
A commanding officer, abbreviated CO, skipper, or ship's captain was a term used to describe one's hierarchical position in relation to others within the same environment. On starships, it was general practice to address the commanding officer as "captain", regardless of their actual rank or position. Proper naval parlance said that, even if a vessel was commanded by an officer whose rank was lower than captain, that officer was still able to be referred to as a captain while on the deck of their own vessel, no matter their literal commissioned rank. In some cases, the term "commander" was the chosen title. (DS9: "Behind the Lines")
One meaning of commanding officer was the highest-ranking officer and commander of a unit. On starships, the CO usually held the rank of captain, though sometimes a commodore or fleet captain may have also held this position. On starbases, the CO was sometimes referred to as "portmaster" and was usually a flag officer. (TOS: "Court Martial", "The Menagerie, Part I", "The Menagerie, Part II", "The Deadly Years") Some bases, however, were commanded by commodores, captains or commanders. (Star Trek: Deep Space Nine seasons 1-3; TNG: "11001001"; TOS: "Balance of Terror", "Court Martial", "The Menagerie, Part I", "Arena", "The Deadly Years")
Aboard starships, it was the commanding officer's duty, "whether pleasant or unpleasant, to listen to the reports, observations, even speculations, on any subject that might affect the safety" of their vessel. (TOS: "Where No Man Has Gone Before")
Commodore Matt Decker, mournful of the loss of his ship and crew, explained his rational for his suicide run at the "planet killer", stating, "The commander is responsible for the lives of his crew… and for their deaths. Well… I should have died with mine." Kirk, in turn pleaded "You can't throw your life away like this. Matt, you're a starship commander. That makes you a valuable commodity. We need you… your experience, your judgment. Matt! We're stronger with you than without you!" (TOS: "The Doomsday Machine")
It was also possible for lower ranks to be the commanding officer aboard a starship, such as the case with Lieutenant Commander Tom Markel aboard the USS Ariel. (TAS: "The Eye of the Beholder") Other examples included Starfleet Command temporarily assigning a number of officers to command vessels that blockaded the Romulan support of the House of Duras in 2368, including Lt. Cmdr. Data aboard the USS Sutherland. (TNG: "Redemption II") Lieutenant Commander Piersall commanded the USS Prometheus in 2370. (DS9: "Second Sight") Benjamin Sisko commanded the Defiant as a commander for nearly a year before he was promoted to captain. (DS9: "The Search, Part I", "The Adversary") Major Kira Nerys and Lieutenant Commanders Jadzia Dax and Worf commanded the USS Defiant on a number of occasions. In 2373, Major Kira commanded the Defiant to destroy a Klingon minefield near the Bajoran system. Commander Worf assisted Captain Sisko in 2372 by bringing the Defiant to Earth to help quash Admiral Leyton's attempted coup d'état. Later, Worf helped his former commanding officer, Captain Jean-Luc Picard, in the Battle of Sector 001. Commander Dax commanded the Defiant in 2374 while operating out of Starbase 375. Her mission was to destroy a Dominion sensor array hidden in the Argolis Cluster. (DS9: "Sons of Mogh", "Paradise Lost", "Behind the Lines"; Star Trek: First Contact)
Captain was a title typically held by commanders of merchant vessels and sometimes service craft. In 2367, Wesley Crusher remarked in a bemused manner that Dirgo was claiming to hold the rank of captain while serving as the master of the mining shuttle Nenebek. To this, Dirgo sternly told Crusher that yes, indeed, his rank was that of captain in comparison to Crusher's rank of ensign. (TNG: "Final Mission")
Chain of command
The term "commanding officer" could also be used to refer to the officer whom one directly reported to in the chain of command or in a department. Occasionally, it simply identified an officer of higher rank in comparison to another, or the officer with the most experience if more than one officer held the highest rank at the time, although this was usually referred to as a ranking officer.
Kirk, who greatly lamented the loss of three security men on Gamma Trianguli VI, had his self-recriminations reassured by Spock, who explained that "No one has ever stated that Starfleet duty was particularly safe. You've followed the correct and logical course, done everything a commander could do." (TOS: "The Apple")
Riker again brought up the issue of one's commanding officer when he, under threats by Arctus Baran, demanded that Data withdraw the USS Enterprise-D from their attempt to stop Baran's mercenary ship. (TNG: "Gambit, Part I")