Screen and VI

Giorgos Keramidas keramida at
Sun May 25 23:58:48 PDT 2003

On 2003-05-25 17:01, Jerry McAllister <jerrymc at> wrote:
> >
> > Anyone know why, while in screen if i move the cursor (arrow key on
> > keyboard) right i get the letter C ? (inside vi)
> Probably the arrow key sends ESC-C as its code.  something eats the ESC
> and that leaves C.

The arrow keys work fine in 'command mode' in vi(1) if TERM is set
properly in the environment.  In insert mode they don't but that's not
very bad.  They do work in vi clones from the ports, like vim, though.

> All the extra keys such as arrows, page up, down, etc send ESC sequence
> codes -I don't know all the codes.  They're probably documented somewhere.
> Most are versions are probably based on the DEC VT100 and VT200 codes from
> back in ancient history.

The termcap sources are the definitive guide for finding out what each
terminal expects.  Alas, they're not very human-friendly to read.

> Generally we tell people not to use the arrow keys with in vi, but if
> your terminal configuration is set up right and your network is fast
> you can do it.    So, you have to figure out how to set up TERM.
> Maybe someone else will know the actuall setting information.

I usually fire up screen(1) in my console ttys or xterm windows, and
then set TERM=vt220.  This is monochrome, but all the arrow keys work
fine.  I even managed to make ALL the special keys like Insert, DEL,
Home, End, PageDown and PageUp to work 'as expected' in Emacs with the
following bindings in my .emacs file:

    ;; Key bindings.
    (global-set-key "\C-c,"  'goto-line)
    (global-set-key "\C-cw"  'delete-trailing-whitespace)
    (global-set-key "\C-xrs" 'bookmark-save)
    (global-set-key "\C-s" 'isearch-forward-regexp)
    (global-set-key "\C-r" 'isearch-backward-regexp)

    ;; Some bindings to make using Emacs nicer on vt220 terminals.
    (global-set-key "\C-h"          'backward-delete-char)
    (global-set-key [delete]        'delete-char)
    (global-set-key [deletechar]    'backward-delete-char)
    (global-set-key "\M-\C-h"       'backward-kill-word)
    (global-set-key [home]          'beginning-of-line)
    (global-set-key [find]          'beginning-of-line)
    (global-set-key [end]           'end-of-line)
    (global-set-key [select]        'end-of-line)

- Giorgos

More information about the freebsd-questions mailing list