Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backspace deletes characters forward like the delete key in vim when using term=xterm #641

Closed
etheralm opened this issue Apr 15, 2016 · 30 comments

Comments

@etheralm
Copy link

@etheralm etheralm commented Apr 15, 2016

In the apha and preview releases of ConEmu Backspace deletes characters forward from the cursor like the delete key when I switch to xterm in vim.

When I do :echo getchar() I get the following sequence back in vim: <80>^D<80>kD
problem

This is not the case in the Stable version. There I get back the correct sequence: <80>kb
bnormal

@Maximus5
Copy link
Owner

@Maximus5 Maximus5 commented Apr 15, 2016

  1. Screenshots are cropped. I need StatusBar.
  2. I have no idea what of numerous versions of vim do you run, what shell you are using, what bundle, and so on.
  3. Also I need screenshot of Settings/Info.

Guidelines for CONTRIBUTING

@etheralm
Copy link
Author

@etheralm etheralm commented Apr 15, 2016

Windows 8.1 64bit
Shell is cmd.exe
vim version is 7.4.1721, the latest 64bit windows version downloaded http://www.vim.org/download.php not the cygwin version.

The bundle is my own vim config, but I removed it and applied only the settings that you can see in the screenshots below. Let me know if you need anything else.

Alpha:
bug

Stable:
bnormal

Maximus5 added a commit that referenced this issue Apr 17, 2016
  It was posted with LEFT_CTRL_PRESSED in dwControlKeyState. We are posting `<BS>`, but not a `<Ctrl>-<BS>`.
@Maximus5
Copy link
Owner

@Maximus5 Maximus5 commented Apr 17, 2016

Regardless of the 67b809d, I consider this is a bug (or configuration problem) of the official vim.
Both cygwin and msys2 versions do not have problems with <BS> key. With or without connector - does not matter.

BTW, strange that my "official" vim prints weird characters on :echo getchar().

Key echo result
<Del> ЂэP
<BS> ЂkD
@etheralm
Copy link
Author

@etheralm etheralm commented Apr 20, 2016

Just tested it, vim reports back <80>kD now, instead of <80>^D<80>kD. The problem is that kD is the delete key and it still deletes characters forward from the cursor when you press backspace.

Btw I just had a look and it seems that 0x7F is ASCII Delete in xterm, Backspace is 0x08. I'm not sure if this would help.

Screenshot:
meh

@Maximus5
Copy link
Owner

@Maximus5 Maximus5 commented Apr 20, 2016

seems that 0x7F is ASCII Delete in xterm, Backspace is 0x08

Show the proof link.

0x7F is equivalent for ^? which may be "typed" with BS hey. This is so on every terminal I've tried.
Proof: https://en.m.wikipedia.org/wiki/Delete_character

As I said, it seems like a bug in the official vim bundle.

@etheralm
Copy link
Author

@etheralm etheralm commented Apr 20, 2016

Show the proof link.
https://en.wikipedia.org/wiki/Control_character#In_ASCII

Gvim shows <80>kb same as wtih the stable verson of Conemu

screenshot from gvim:
gvim

@Maximus5
Copy link
Owner

@Maximus5 Maximus5 commented Apr 20, 2016

https://en.wikipedia.org/wiki/Control_character#In_ASCII

True for Windows consoles. But seems like Unix terminals (which vim was developed for) uses other notation, not just a ASCII codes. For example Del is represented with \e[3~. And BS - 0x7F. Link above.

Gvim shows <80>kb

What do you mean?

@etheralm
Copy link
Author

@etheralm etheralm commented Apr 20, 2016

What do you mean?

In gvim when I do :echo getchar() and press backspace I get back <80>kb as shown on the screenshot.

True for Windows consoles. But seems like Unix terminals (which vim was developed for) uses other notation, not just a ASCII codes.

Yes I understand and I have no idea how the mapping is done between conemu and vim when run in cmd.exe.

I am just saying that the backspace key is working as expected when I run the stable conemu version(150813g), it may very well be a bug in the official vim bundle,

@Maximus5
Copy link
Owner

@Maximus5 Maximus5 commented Apr 20, 2016

backspace key is working as expected when I run the stable conemu version(150813g)

Sure it was. Stable had a bug, the BS key was not translated to corresponding xterm sequence. It is translated now, but vim do not understand it. BTW, googling shows a lot of problems with configuring BS/Del in vim in different terminals.

@etheralm
Copy link
Author

@etheralm etheralm commented Apr 20, 2016

Thanks for your time investigating this. I'll have a look if I can dig out something about it.

@etheralm
Copy link
Author

@etheralm etheralm commented Apr 21, 2016

I did some experimenting and got the following results, I used ctrl+v in vim to capture the raw character:

In all terminals that I tested the delete key sends the correct sequence: ^[[3~

In linux using the gnome terminal, the character I got when I press backpace is: ^?
In windows using cmd.exe without conemu I got: ^H
When using cmd.exe with conemu stable I got back also ^H.
When using cmd.exe with the latest conemu I got the 0x07f character.
With cygwin terminal I got ^H

I hope this would help.

Anyway I managed to work around this by setting the following option in vim:
inoremap <Char-0x07F> <BS>
nnoremap <Char-0x07F> <BS>

@dphuang2
Copy link

@dphuang2 dphuang2 commented May 22, 2016

@etheralm thank you for investigating. I had this exact same problem with ConEmu version 160515. I just copy and pasted

inoremap <Char-0x07F> <BS>
nnoremap <Char-0x07F> <BS>

into my .vimrc and it fixed the issue.

@Konfekt
Copy link

@Konfekt Konfekt commented May 28, 2016

Thanks a lot! Exactly the same issue over here with ConEmu 160522.

@danwagnerco
Copy link

@danwagnerco danwagnerco commented Jun 14, 2016

Just updated to the stable version 160612 [64 bit], was experiencing the same Backspace / Delete issue here. The @etheralm suggestion of adding:

inoremap <Char-0x07F> <BS>
nnoremap <Char-0x07F> <BS>

to my _vimrc fixed the behavior! 👍

@Kazark
Copy link

@Kazark Kazark commented Jun 17, 2016

Can repro but @etheralm 's fix worked for me. Thanks!

@jpkontreras
Copy link

@jpkontreras jpkontreras commented Aug 24, 2016

same happening with gitbash 2.9.1 X64

orient-man added a commit to orient-man/vimfiles that referenced this issue Oct 31, 2016
@Hylian
Copy link

@Hylian Hylian commented Dec 8, 2016

@etheralm's fix didn't quite do it for me, but this seems to work just fine for me:

set backspace=indent,eol,start
inoremap <Char-0x07F> <c-r>=Backspace()<CR>
inoremap <BS> <c-r>=Backspace()<CR>

func Backspace()
  if col('.') == 1
    if line('.')  != 1
      return  "\<ESC>kA\<Del>"
    else
      return ""
    endif
  else
    return "\<Left>\<Del>"
  endif
endfunc

@austincrft
Copy link

@austincrft austincrft commented Jan 12, 2017

Do any of you use the CtrlP plugin? I'm not able to backspace in the CtrlP prompt. 😞

@Hylian
Copy link

@Hylian Hylian commented Jan 12, 2017

@austincrft
Copy link

@austincrft austincrft commented Jan 12, 2017

Ah, it's because we remapped <BS> to get it working in normal and insert mode. This makes backspace work in the prompt for me.

Note that you'll want to wrap a if !empty($CONEMUBUILD) or if has('win32') around this if you share your vimrc across operating systems.

let g:ctrlp_prompt_mappings = {
    \ 'PrtBS()': ['<Char-0x07F>', '<c-h>']
\ }
@noumenonquest
Copy link

@noumenonquest noumenonquest commented Apr 29, 2017

The solutions mentioned above

inoremap <Char-0x07F> <BS>
nnoremap <Char-0x07F> <BS>

and

set backspace=indent,eol,start
inoremap <Char-0x07F> <c-r>=Backspace()<CR>
inoremap <BS> <c-r>=Backspace()<CR>

func Backspace()
  if col('.') == 1
    if line('.')  != 1
      return  "\<ESC>kA\<Del>"
    else
      return ""
    endif
  else
    return "\<Left>\<Del>"
  endif
endfunc

doesn't work, backspace deletes one character and does not move left, but just stays at the same position, does anyone know a fix for that??

@jarrodhroberson
Copy link

@jarrodhroberson jarrodhroberson commented Jun 7, 2017

So what does one have to do to get this fixed? It used to work on my old machine, but I had to reinstall on a new laptop and now BACKSPACE does DELETE and none of the "fixes" make any difference.

@Maximus5
Copy link
Owner

@Maximus5 Maximus5 commented Jun 8, 2017

Read the links I've posted here. Especially this one: http://conemu.github.io/en/VimXterm.html#vim-bs-issue

Actually, if you have access to your old machine, it would be easy to compare configs or anything else.

@flipcoder
Copy link

@flipcoder flipcoder commented Jul 17, 2017

For people who are still having the problem, a vim plugin is likely mapping backspace or ctrl-h

Check which script is doing it by looking at the output of:

:verbose map <bs>
:verbose map <c-h>

Disable the problem plugins. This is what I had to do.

@Maximus5 Maximus5 closed this Aug 5, 2017
@git-rb
Copy link

@git-rb git-rb commented Sep 28, 2017

Looks like vim indeed selects the wrong terminal sequences for both backspace and delete at startup, ConEmu is sending the correct codes..

I fixed with the following in vimrc:
let &t_kb = nr2char(127)
let &t_kD = "^[[3~"

janlazo added a commit to janlazo/dotvim8 that referenced this issue Jan 9, 2018
@hulucc
Copy link

@hulucc hulucc commented Jun 29, 2018

let &t_kb = nr2char(127)
let &t_kD = "^[[3~"

This will make ^(to the first non-blank character of the line) extermely slow

@wave-blessed
Copy link

@wave-blessed wave-blessed commented Feb 18, 2020

Vim 8.2 totaly broke BS. Comparing 8.1 and earlier.

Короче говоря, вим 8.2 с одной-единственной строчкой в конфиге set term=xterm творит с бэкспейсом чудеса, и не помогает добавление inoremap <Char-0x07F> <BS> В предыдущих версиях — 8.1 - 7.4 проблем не было, а тут самое мягкое — вставляет вместо бэкспейса комбинацию Îx. Я далеко не продвинутый пользователь вима, но абсолютно заколебался, пытаясь решить эту проблему самостоятельно. Гуглил, методом половинного деления отключал куски конфигов и плагины, искал, какая сволочь сама мапится на бэкспейс :verbose map <bs> (спойлер: никакая), искал, как перемапить самому, по примеру вышеуказанного inoremap <Char-0x07F> <BS> но так и не нашёл, каким образом нужно записывать этот Îx, чтобы вим понимал, что я от него хочу.

Пока что у меня два выхода: привыкнуть к хоткеям Ctrl+H и Ctrl+W или сидеть на версии 8.1.

P.s. По некоторым причинам в конфиге ConEmu у меня добавлено chcp 65001 и соответствующие правки в конфиге вима: set encoding=utf-8 и set termencoding=utf-8

@vladkosarev
Copy link

@vladkosarev vladkosarev commented Feb 21, 2020

Getting the same in 8.2
None of the fixes work. Extremely annoying.

@Avi0
Copy link

@Avi0 Avi0 commented Jul 18, 2020

Vim 8.2 totaly broke BS. Comparing 8.1 and earlier.

I confirm the problem still exists. Just upgraded to Vim 8.2 and having exactly the same experience. This is not related to ConEmu, it's the same in Windows Terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.