Fixing the arrow keys in Vim

Are your Vim / Vi arrow keys making A,C, B etc characters instead of moving around in insert (‘i’) mode ?

Try typing this … it fixes it for me:

:set nocompatible

Or, add the line:

set nocompatible

to your ~/.vimrc file.

34 thoughts on “Fixing the arrow keys in Vim

  1. In my Ubuntu the setting in /etc/vim/vimrc.tiny had a “set compatible” line. I commented it out and everything is OK for all users…

  2. The default vim installed with Ubuntu is pretty weak. Fix all arrow movement, backspacing, etc problems with:

    sudo apt-get install vim

  3. Thank you blog author and also thank you Trent; it seems ubuntu and debian share this odd quirk of bundled vim sucking compared to the version available in repo. I just “aptitude install vim” and it installs — even though it was already there — then suddenly this and many other problems vanish into a puff of logic.

  4. This is the normal behavior of vim when be called by ‘vi’ name.
    Instead of changing the normal behavior, change your call instead by using ‘vim’ or add the following to your /etc/bash.bashrc :
    alias vi=vim (or vim.tiny)

  5. Wow, I just updated to 12.04 and the vi in it was driving me …….

    Thank you so much for this one!
    (I just edited /etc/vim/vimrc.tiny to set nocompatible)

  6. hey it was really helpful n it solved a big problem. but will u explain to me what was the reason of the unexpected behaviour of arrow keys and what happens when setting no compatible in .vmrc file pls?

  7. Hi Aparna – I think you’ll find the answer in the comments above (by Trent, Jesse and mjdtjm).

    Essentially, the default version of ‘vi’ that comes with Ubuntu is ‘vim-tiny’ and the alternatives system links this to the ‘vi’ command. The original legacy Unix ‘vi’ didn’t support the nicer arrow key cursor navigation supported by ‘vim’ (Vi Improved). To ensure backward compatibility, the default version of ‘vi’ installed is set to compatible mode, which means the cursor keys don’t work as we might expect on a modern system.

    By setting ‘nocompatible’ in your .vimrc, you are telling vi (which is ‘vim-tiny’ by default) to act like the newer nicer ‘vim’ rather than old school ‘vi’. Since the change is to the config file in your home directory, this will only effect your user login, not the entire system.

    An alternative, mentioned by Trent, would be to:

    sudo apt-get install vim

    This way you get ‘real’ vim, not ‘vim-tiny’.

  8. Well atleast there is still ed, the classic unix editor which you are likely to find on all distributions, Oh except idiotic ones like Arch Linux.

  9. Thanks very much! Changing /.vimrc didn’t work for me, but Brian’s comment of
    “For vi, you need to add the “set nocompatible” line to ~/.exrc”
    Sorted my problem! I was sshing from Mac OS X to Ubuntu 14.04 on Virtubox.

Leave a Reply

Your email address will not be published. Required fields are marked *