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 · 27 comments

Comments

Projects
None yet
@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

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Apr 15, 2016

Owner
  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

Owner

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

This comment has been minimized.

Show comment
Hide comment
@etheralm

etheralm 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

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

gh-641: Correct posting `0x7F` (which is `<BS>` on xterm) to console.
  It was posted with LEFT_CTRL_PRESSED in dwControlKeyState. We are posting `<BS>`, but not a `<Ctrl>-<BS>`.
@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Apr 17, 2016

Owner

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
Owner

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

This comment has been minimized.

Show comment
Hide comment
@etheralm

etheralm 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

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

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Apr 20, 2016

Owner

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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@etheralm

etheralm 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

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

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Apr 20, 2016

Owner

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?

Owner

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

This comment has been minimized.

Show comment
Hide comment
@etheralm

etheralm 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,

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

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Apr 20, 2016

Owner

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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@etheralm

etheralm Apr 20, 2016

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

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

This comment has been minimized.

Show comment
Hide comment
@etheralm

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

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

This comment has been minimized.

Show comment
Hide comment
@dphuang2

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

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

This comment has been minimized.

Show comment
Hide comment
@Konfekt

Konfekt May 28, 2016

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

Konfekt commented May 28, 2016

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

@danwagnerco

This comment has been minimized.

Show comment
Hide comment
@danwagnerco

danwagnerco 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! 👍

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

This comment has been minimized.

Show comment
Hide comment
@Kazark

Kazark Jun 17, 2016

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

Kazark commented Jun 17, 2016

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

@jpkontreras

This comment has been minimized.

Show comment
Hide comment
@jpkontreras

jpkontreras Aug 24, 2016

same happening with gitbash 2.9.1 X64

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

This comment has been minimized.

Show comment
Hide comment
@Hylian

Hylian 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

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

This comment has been minimized.

Show comment
Hide comment
@austincrft

austincrft Jan 12, 2017

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

austincrft commented Jan 12, 2017

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

@Hylian

This comment has been minimized.

Show comment
Hide comment
@Hylian

Hylian Jan 12, 2017

Hylian commented Jan 12, 2017

@austincrft

This comment has been minimized.

Show comment
Hide comment
@austincrft

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

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

This comment has been minimized.

Show comment
Hide comment
@noumenonquest

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

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

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@jarrodhroberson

This comment has been minimized.

Show comment
Hide comment
@jarrodhroberson

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

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

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jun 8, 2017

Owner

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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@flipcoder

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

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

This comment has been minimized.

Show comment
Hide comment
@git-rb

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

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

@hulucc

This comment has been minimized.

Show comment
Hide comment
@hulucc

hulucc 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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment