I think I know what's going on.
You've not configured
vim to disable
vi compatibility mode.
vi, you can only press the arrow keys in command mode. When in insert mode, the character sequences sent upon pressing the arrow keys are treated as if the characters were entered individually.
Now, upon startup,
vi sets the terminal in keypad transmit mode (kx). In that mode, the terminals usually send a different character sequence upon pressing the arrow keys than when not.
For instance, the Up key sends
\eOA in kx mode and
\e[A when not.
To set the terminal in kx mode, it looks up the
smkx (Set Mode Keypad Transmit) capability in the terminfo database for the current value of
If you look at the
smkx capability for
linux, you see:
$ infocmp -1 linux | grep smkx
$ infocmp -1 xterm | grep smkx
$ infocmp -1 konsole | grep smkx
smkx is not defined in the
What that means is that when you start
TERM=linux, vim doesn't set the terminal in kx mode, that means it sends
\e[A instead of
\eOA when you press the Up key for instance.
Now, what does
\eOA do in vim when you're in insert mode?
\e (ESC), leaves insert mode and returns to command mode.
O opens a new line and enters insert mode again,
A inserts the
\e (ESC) leaves insert mode,
[A is an unknown combination (in
[ is a prefix and is always followed by another character), so does nothing.
So what you need to do is: keep
$TERM as it is, don't use arrow keys in insert mode when in vi compatibility or add a
set nocp to your
~/.vimrc so you can use arrow keys in insert mode.