This problem only happens in Gvim. It does not happen in the console version of vim. I'm running Gvim 7.2.245 on a Ubuntu 9.10 machine.
After opening Gvim, I can type :sh and get to the shell prompt. I can then execute a command (eg ls). However, if I want to execute that command again by pressing the "up" arrow key, I can a garbled mess of what looks like some binary and then the letters "ku". Similarly pressing the "down" arrow gives the same result followed by the letters "kd".
If I press ESC then one of the arrow keys, I ONLY get the letters (eg "ku") without the garbled binary.
Perhaps this issue has something to do with text-terminals and vim cursor-keys or something. Does anyone have the answer to it?