I was wondering if the famous "small step for man, huge leap for mankind" quote was something Armstrong originally planned of saying with maybe NASA or the PR guys. Or was it literally just a spur of the moment thing?
Yes, and he flubbed it.
He was supposed to say, "One small step for a man, one giant leap for mankind."
He left out the 'a', making his line almost contradict itself since man and mankind are virtually the same thing.
Specifically, the quote is "One small step for man, one giant leap for mankind." But that's apparently not what Armstrong meant to say. The journalists that were covering the historical event were able to listen in on the transmissions between the astronauts and mission control. They typed and dictated and captured everything of significance as the module approached the surface. And then, the moment of truth... the eagle had landed, and Armstrong emerged from the module. His boot landed on the surface, and he said the line.
But what did he say? There was some debate; Joel Shurkin, who was there covering the story, said:
Eventually Armstrong climbed down the lunar module’s ladder and set foot on the surface, a step guaranteed to put his name in every history book ever. And then he said either “that’s one small step for man, one giant leap for mankind,” or “that’s one small step for a man, one giant leap for mankind.” The transmission was not clear and we were not sure we heard the word “a” before the word “man.”
Now we had problem and no time to think about it. Clearly, this was to be one of the most famous quotations in history and we had to get it right. More important at the moment, we had to be consistent. We could not have one news service say one thing, the other two something else, or have the New York Times have one version and the Washington Post another. Forget history, we had to deal with editors.
Those present collectively decided that he had not said the 'a'- that the quote was "one small step for man." Armstrong later insisted that he had planned what he was going to say, and that he had said "a man." However, NASA later released the transmission (cleaned up) and it was clear that he had not said the 'a.' He intended to, but apparently forgot. I'd image the stage fright might have been a factor, what with the whole world watching and all.
So, to more directly answer your question, Armstrong had planned his speech before landing, but made a small mistake that significantly changed the meaning.
Source for above: Joel Shurkin
There are more recent claims that accoustic analysis and improved technology picked up on the missing 'a,' but there is no consensus among the experts and the test results have been mixed. Because of this, NASA still has the 'a' in brackets to indicate that the word was intended, but missing.
In 1983, Armstrong told journalist George Plimpton that he had planned the words in advance, but not far in advance. According to Armstrong, he "had produced the lines on his own ... and the words were composed not on the long trip up there, as had been supposed by most of his colleagues, nor beforehand but after the actual landing of Eagle on the moon's surface." Armstrong explained that he hadn't spent much time thinking of what to say, because he felt there was a very significant possibility that they would have to abort the landing. "I always knew there was a good chance of being able to return to Earth, but I thought the chances of a successful touchdown on the moon surface were about even money—fifty-fifty ... Most people don't realize how difficult the mission was. So it didn't seem to me there was much point in thinking of something to say if we'd have to abort landing."
So Armstrong did plan what to say before he left the module, but not very long before. And there is no evidence that NASA or any PR folks wrote or knew what he was going to say.