Conemu: backspace deletes characters forward like the delete key in vim when using term=xterm

Created on 15 Apr 2016  Β·  30Comments  Β·  Source: Maximus5/ConEmu

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

other-vim status-unanswered

Most helpful comment

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>

All 30 comments

  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

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

Regardless of the 67b809d5f, 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 |

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

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.

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

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?

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,

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.

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

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>

@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.

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

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! :+1:

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

same happening with gitbash 2.9.1 X64

@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

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

I was able to backspace in CtrlP by pressing Ctrl+H.

On Jan 12, 2017 4:16 PM, "Austin Craft" notifications@github.com wrote:

Do any of you use the CtrlP plugin https://github.com/ctrlpvim/ctrlp.vim?
I'm not able to backspace in the CtrlP prompt. 😞

β€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/Maximus5/ConEmu/issues/641#issuecomment-272285898,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAReCpxrmukcmssuovJzVGz2OXFAwYPcks5rRpgggaJpZM4IIP3b
.

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>']
\ }

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

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.

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.

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.

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~"

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

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

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

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MandarSant picture MandarSant  Β·  3Comments

Daniel15 picture Daniel15  Β·  3Comments

jrcharney picture jrcharney  Β·  5Comments

eblis picture eblis  Β·  5Comments

pyhedgehog picture pyhedgehog  Β·  3Comments