Fix for Vi’s broken arrow key support in iTerm

So, I got turned on to iTerm, a prettier and more user-friendly alternative to Apple’s native Terminal.app.

However, for some reason, I got the following error message whenever I tried to use arrow keys in Vi:

Usage: [[

The problem is that Vi is faithfully responding to the TERM variable that iTerm is sending. (I’m not sure why Terminal.app and PuTTY don’t suffer from this issue, but c’est la vie.) So, you should keep the terminal setting in iTerm to xterm-color, since this is great for most things, but then add this setting to your .exrc file to tame Vi:

set term=linux

Not sure why this fixes it, but it does. set term=cons25 was another fix that I found, but it seems to break if you have line numbers turned on, because all tab characters are turned into backticks (`).

6 Responses to “Fix for Vi’s broken arrow key support in iTerm”

  1. On April 17th, 2007 at 14:11:44, radius Said:

    thank you so much for this fix.
    This has pissed me off to no end since i upgraded my older version of iterm. i was starting to resort to Terminal.app, which no one should have to do.

    keep up the good work, homie.

  2. On April 17th, 2007 at 15:56:50, Isaac Said:

    Actually, I just found that the same problems show up using the more and less commands. They worked right with the hjkl keys, however, just like Vi.

    I just changed my default terminal profile in iTerm to “linux” and now everything works right with arrow keys.

  3. On April 17th, 2007 at 16:38:26, radius Said:

    Nice. That one worked for me as well. Thanks again.

  4. On June 25th, 2007 at 17:34:44, benstiglitz Said:

    FWIW, here’s what’s going on:

    The default termcap on Mac OS X specifies that applications should enter application-specific cursor mode when capturing the display. iTerm is faithfully sending the application-mode sequences, but most terminal emulators just ignore the app-mode escape sequences and send normal key sequences instead.

  5. On August 24th, 2007 at 07:31:13, Higgaion Said:

    in case you use more than one terminal app, you can add this to your .vimrc:


    if $TERM_PROGRAM == 'iTerm.app'
    set term=linux
    endif

  6. On September 24th, 2007 at 10:04:32, Foo Hack » Fix for Vi’s broken arrow key support in iTerm Said:

    [...] originally posted this at isaacschlueter.com on Tuesday, April 17th, 2007. I’ve incorporated the info from the comments into the main [...]

Leave a Reply

Comments are moderated like crazy using a variety of plugins. There is a very high likelihood that your comment won't show up right away, especially if you have never commented here before, but it was not deleted.

Please be patient, and do not post your comment more than once. It will show up once it is approved.

You must be logged in to post a comment.