Vim, Terminal.app, and the Delete key
One of my SSH servers continually gives me problems with the Mac
"Delete" key in Vim. While the key always works correctly in bash, it
will only work in Vim if I am inside a screen session. If I have not
opened screen, Delete will function as "Forward Delete." Oddly, the key
^H in both cases. This turned out to be a termcode issue.
Fixing by Setting \$TERM
I failed to fix this with
~/.inputrc, but did have success after
$TERM. Initially my
$TERM=xterm-color, which fails. When
$TERM=screen, Delete works. Setting
$TERM=xterm works, as well,
which means the following in
~/.bashrc can be used as a fix:
if [ "$TERM" = "xterm-color" ]; then export TERM=xterm fi
Fixing by Remapping Delete
A second solution is to change Vim's terminal options.
:set termcap will show you what t_kD (
<Del>) is currently set to.
When I'm using
TERM=xterm-color, that value is
^H. Remapping t_kD
in .vimrc makes Delete consistent across
Use the modifier keys Ctrl-v and fn-Delete, which will expand to
set t_kD=^[[3~. Best practices would probably explicitly set t_kb
(backspace) as well.