messaliberty

about hulor and us

How to disable the arrow keys in vi or vim

If you are learning to use vi or vim, one of the recommendations is not to use the arrow keys (cursor keys) but instead use the hjkl keys.  There are two main reasons for this:

  • Speed.  After you learn to use the hjkl keys, they are much faster since your hands can stay on the home row.
  • Universality. In some older systems, vim may not be installed and the original vi doesn’t use the arrow keys.

But if you are just starting to learn to use vi, how can you force yourself to use the hjkl keys?  The easiest way is to disable the arrow keys, which is simple if you know how but hard if you are just starting out. To disable the arrow keys, the best way is to use the key remapping functions and save these in your .vimrc file.  If like me, you use Windows, OSX and Linux you can copy these lines to all your .vimrc files.  I mention this because I’ve seen other recommendations using system key remapping.

And here are the magic lines

 noremap  <Up> ""
 noremap! <Up> <Esc>
 noremap  <Down> ""
 noremap! <Down> <Esc>
 noremap  <Left> ""
 noremap! <Left> <Esc>
 noremap  <Right> ""
 noremap! <Right> <Esc>
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • Technorati
  • MySpace
  • Tumblr
  • Yahoo! Buzz
  • Twitter

Related posts:

  1. How to create a single wp-config file for local and remote WordPress development If you are developing WordPress sites, themes or plugins, you...

Related posts brought to you by Yet Another Related Posts Plugin.

4 Responses to “How to disable the arrow keys in vi or vim”

  1. hamazy says:

    Hi, Ian. Here is another way I personally chose: Use a keyboard without any arrow keys!

    BTW, vimtutor command is a very good introduction to vi/vim. I always recommend this to any vi/vim newbies.

  2. ianc says:

    ah but I need my arrow keys in Illustrator :p

  3. Mathias S says:

    Great tip. I have so hard keeping away from the arrows but now I have no choice :)

    Already noticing that i’m using better ways than the arrows for navigation…..

    Thanks mate!

  4. ianc says:

    Glad that it’s helped you Mathias. The only other thing I would advise is trying to use vi/vim for everything. I get lazy and fire up textedit from time to time…

Leave a Reply