vim backspace leaves ^?

2019-01-16 05:40发布

In Vim, when I hit the backspace key in the insert mode, it leaves ^? character and does not delete the character it is suppose to delete.

I have the following in my .vimrc

syntax on
set number
set expandtab
set incsearch
set nocompatible
set backspace=indent,eol,start
fixdel

This happens in the command mode too. When I wrongly type W instead of w to save, I press backspace key and it gives me the following:

:W^?

Any idea on whats wrong and how to fix it?!

UPDATE: before posting this question to SO, I have done a basic google search and tried all the suggestion from the first page of search result but unsuccessful.

@strcat I'm using vim version 7.0.237, KDE console 1.6.4, Linux 2.6.18 x86_64 machine.

@graywh w.r.t cat -v, for delete, I get ^[[3~ and for backspace, I get ^?.

The output of stty -a is as follows

speed 38400 baud; rows 38; columns 194; line = 0;
intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O;
min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -cdtrdsr
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -ixon -ixoff -iuclc -ixany -imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

14条回答
一纸荒年 Trace。
2楼-- · 2019-01-16 06:20

^? 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.

查看更多
贼婆χ
3楼-- · 2019-01-16 06:21

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
查看更多
Emotional °昔
4楼-- · 2019-01-16 06:21

I had this problem and found the following setting in my .vimrc:

:set t_kb=^H

Removing that line solved the problem.

查看更多
冷血范
5楼-- · 2019-01-16 06:24

I had the same issue where vim backspace leaves ^?, while in command line it worked properly.

This is what worked for me, using vim mapping:

In .vimrc, type:      imap ^? ^H

This will map CTRL-H (which is the default backspace in vim) to the backspace key. Hope that helps.

查看更多
可以哭但决不认输i
6楼-- · 2019-01-16 06:27

A good fix for this problem is to set the "Terminal > Keyboard" settings to map the Backspace key to "Control-H" in PuTTY; This is if you are using PuTTY and experiencing the "^?" problem when pressing the Backspace key.

I've created an article on this here:

https://alvinbunk.wordpress.com/2017/08/23/vi-or-vim-using-backspace-inserts/

Thanks to @j03m for the suggestion!

查看更多
7楼-- · 2019-01-16 06:28

Please check the link bellow to help debug your problem:

http://vim.wikia.com/wiki/Backspace_and_delete_problems

EDIT:

i found what it seems like a similar problem with the one described by you:

http://lj4newbies.blogspot.com/2007/05/backspace-and-delete-keys-problem-in.html

查看更多
登录 后发表回答