In emacs, when i am editing a program, and miss-input some command and make the cursor jump to somewhere in other files. Is there a short-cut key or command to jump back to the last location of the cursor?
I believe what you are searching for is
The global mark ring is updated automatically on many occasions such as buffer switching, accidental or otherwise.
You can use the command previous-buffer which in my version (GNU Emacs 23.2.1) is bound to
Just type Meta-x describe-key C-x left for further information
There is also winner-mode that binds
It will also highlight everything between your previous cursor location and the new location (if you want to get rid of the highlighting, just C-g). You can set the location where you will jump back to with C-space. So, for example, you might plan to use this with:
cursor at the start of a paragraph
move cursor to the end of the paragraph
(the entire paragraph is now highlighted)
(the paragraph is now in the copy buffer, ready to be pasted elsewhere with C-y)