vim backspace leaves ^?

无人久伴 提交于 2019-11-28 03:19:05

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

Try ctrl+del/ctrl+backspace or alt+del/alt+backspace, I cant remember which, but I think it will do the trick for you.

If that doesn't work try shift+backspace/del. I've ran into this problem before, there is a combo key that you can press to send the correct char code to do your deleting.

Taiki

Try adding:

noremap! <C-?> <C-h>

to your ~/.vimrc.

This maps C-? to backspace, and worked for me.

Had exactly same problem, except that Ctrl+H wasn't working for me. stty settings are also fine. Just wanna mention my environment, if somebody will got same problems:

  • Using cygwin with xterm, under X ofcourse :)
  • Ssh'ed to RHEL6.4->bash->tmux->vim

After adding fixdel to .vimrc it works! All fixes above wasn't working for me.

BRASIL

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.

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!

This answer worked for me: http://vim.wikia.com/wiki/Backspace_and_delete_problems

Basically, putting set backspace=2 in .vimrc works.

Parth

put stty erase ^? in your .bashrc

Run your .bashrc

run command: stty -a

speed 38400 baud; rows 48; columns 157; line = 0;
intr = ^C; quit = ^\; ***erase = ^?***; 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

Erase will be changed by now with new value ^? and your backspace shall work now.

On Mac, if you are using Terminal, go to Preferences -> Profiles -> Advanced, then select "Delete Sends Control-H"

If you are using KDE, I know that pain. This is the most comprehensive solution I have found so far http://www.yalla.nu/blog/post/86

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

:set t_kb=^H

Removing that line solved the problem.

Under FreeBSD with CSH you should replace this in your .cshrc:

bindkey "^W" backward-delete-word

With this :

bindkey "^?" backward-delete-word
OmaruSensei

For me, it was a stty problem, I had a similar stty -a output as yours.
It got fixed for me by running stty sane.

Not only did this fix the backspace/del problem, but also fixed the arrow keys.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!