vim backspace leaves ^?
On Mac, if you are using Terminal, go to Preferences -> Profiles -> Advanced, then select "Delete Sends Control-H"
^?
is the delete character; the backspace character is ^H
. Only one of these is recognized by your terminal as "erase", and this is determined by the terminal settings, stty
. (bash and other shells understand this as a problem and do special things to recognize both)
If your terminal emulator (ssh, putty, xterm, whatever) disagrees with your terminal settings, then you see this behavior. Usually it's right by default, but very often people will put stty
commands in their .bashrc which breaks things.
You probably have something like stty erase ^H
in your bashrc. If you do, get rid of it, or change your terminal settings to have backspace send ^H
instead of DEL (^?
)
You can also fix this with vim mappings, but that's ignoring the basic problem.
From the vim wiki Backspace_and_delete_problems, I went on to read :help :fixdel
it suggests this:
if &term == "termname"
set t_kb=^V<BS>
fixdel
endif
Where "^V" is CTRL-V and "" is the backspace key
(don't type four characters!). Replace "termname"
with your terminal name.
For me the fixdel
makes the backspace work like delete. My first mistake was also doing the CTRL-V backspace in gvim, do on the system that you can not get the key to work properly so it pastes the backspace key that the problematic session sees.
I now have in my .vimrc
:
if &term == "xterm-256color"
set t_kb=^?
endif
Try adding:
noremap! <C-?> <C-h>
to your ~/.vimrc
.
This maps C-? to backspace, and worked for me.