When using PuTTY to SSH to a Linux server and edit files, I’ve encountered on several occasions where navigating in vim using the cursor (arrow) keys on the keyboard while in insert mode results in control characters and/or new lines being inserted. Here are a couple of ways to rectify the situation.
- Check if the vim command is pointing to the full version of vim or vim tiny.
$ which vim
Some Linux distros link vim to vim tiny. If it’s pointing to the normal vim, skip to step 4, below.
- If you’re using vim tiny and want to continue to do so, then edit /etc/vim/vimrc.tiny and add the command set nocompatible to turn off compatibility mode.
- If you’d rather have the normal vim editor, then install it. After installation, confirm that the vim command points to the correct version and continue with step 4, below.
- Check that /etc/vim/vimrc (or ~/.vimrc) contains the command, set no compatible, to turn off compatibility mode.
That should do it. If you still have trouble, be sure that your terminal is set correctly in PuTTY and on the remote system.
Have another way to fix this issue? Post it in the comments.