For various historical reasons, it seems to be pretty random what effect
<BkSpc> and
<Del> will have in
different Unix terminals, programs, modes, etc. To make these keys
behave properly in
XTerm,
Gnome Terminal,
Konsole, and
KVT, these settings are needed:
execute 'set t_kb=' . nr2char(8)
fixdel
Note these lines can make things worse if used in another terminal (such
as
RXVT) or when running
Vim with the gui. See
below for how to prevent this happening.
When using some versions of
Gnome Terminal, a completely
spurious “c” character gets output whenever
Vim
is run (though usually it isn’t seen until exiting
Vim). This stops it:
set t_RV=
It is possible to make
Vim automatically do The Right Thing
for the terminal in which it has been run. All of the above-mentioned
terminals claim to have “xterm” in their names, so it is
easy to test for the
term option including this; whenever
Vim’s gui is being used
term will be
something else, and none of these settings will be inadvertently
triggered.
Distinguishing between these terminals is harder. Gnome
Terminal helpfully sets $COLORTERM to
gnome-terminal, but it’s only possible to guess at it
being one of t’others if $COLORTERM is empty.
Fortunately RXVT (for which no prodding is wanted) also sets
$COLORTERM so doesn’t get trapped by this, but
it’s possible that there are other terminals out there that also
have an empty $COLORTERM yet don’t want the same
settings as XTerm et al. Here’s the code:
if &term =~ 'xterm'
if $COLORTERM == 'gnome-terminal'
execute 'set t_kb=' . nr2char(8)
fixdel
set t_RV=
elseif $COLORTERM == ''
execute 'set t_kb=' . nr2char(8)
fixdel
endif
endif
Konsole actually sets
$COLORTERM to an empty
string, but
XTerm and
KVT don’t touch it.
So if one of those two is started from within a terminal that
does set
$COLORTERM, then it will be wrongly
identified as the ‘parent’ terminal.