Latest revision as of 00:29, March 18, 2015

On some systems, you may experience problems using the backspace or delete keys. This tip discusses the causes and solutions. Generally, these problems arise on Unix-based systems because of the wide variety of hardware and software involved.

If your delete key terminal code is wrong, but the code for backspace is alright, you can put this in your vimrc:

:fixdel

This works no matter what the actual code for backspace is.

This is, at best, horrifically misleading. In particular, this will break things for Linux users, and for any other Unix system that has "seen the light". For most modern terminal emulators, <BS> sends ^? and <Del> sends ^[[3~ - and putting :fixdel into your .vimrc will change t_kD from the correct ^[[3~ to the incorrect ^H.

For many terminal emulators, Backspace will send either <C-?> or <C-h>, and Ctrl-Backspace will emit the other. So, if you don't want to spend the time to fix your settings, you might be able to work around your problems using ctrl+backspace instead of backspace.

Your backspace key may be broken due to a bad mapping which has been loaded into Vim. This may be unintentional; Vim sees CTRL-H as a backspace (because CTRL-H is the ASCII code for a backspace), so you also cannot map anything to that. You can check if there are any mappings set, and where they came from, like this:

I got it to work on my system by creating a .vimrc file in the home directory with the line:
set t_kb=^?
where for ^? I pressed backspace. Don't forget to open a new terminal window after your changes in .vimrc

On some Linux systems, pressing backspace in xterm or uxterm will move the cursor left (without deleting the character). To fix, add:

xterm.*backarrowKey: false

To your .Xresources file and run:

xrdb -merge ~/.Xresources

Alternatively, in .vimrc, type this:
"imap ^? ^H"

My terminal sends ^? for backspace and ^[[3~ for delete. To get these keys working in vim like they work in other programs, I put

:set backspace=indent,eol,start
:set t_kb=^?
:set t_kD=^[[3~

into my .vimrc. (Of course, using ^V <backspace> and ^V <delete> to insert the characters.)