Backspace does not work in Cygwin

29

10

I just installed Cygwin and the BACKSPACE functionality is not there, i.e. when I hit the Backspace key, I get a space.

I've been trying to research this issue on Google, but did not find anything conclusive.

user620189

Posted 2011-08-30T14:01:13.413

Reputation: 391

Can you give more details of how you installed and invoked Cygwin, and where exactly the backspace key fails to work? – ak2 – 2011-08-30T14:40:41.727

1I'm guessing this is happening in the shell. What happens when you type control-V followed by backspace? And what's the output of the stty command? – Keith Thompson – 2011-08-30T17:57:12.577

What sort of keyboard do you have? US, UK etc. – pjc50 – 2011-11-07T10:26:25.180

Did you ever resolve this? I'm seeing it now on my new Cygwin install, though it previously worked. It's worth noting that you aren't getting "a space": It's failing to move the cursor back to erase the character. The space you're seeing is the space that was supposed to stomp on the previous character. If you hit ^L you can see that backspace IS working. This is why stty isn't fixing things. It's almost like the CMD shell that Cygwin is bound to is failing to interpret cursor movement. – SomeCallMeTim – 2012-03-19T22:30:52.333

Answers

33

In my case backspace was not at all working after creating blank ~/.vimrc. Following change made it work

Put:

set bs=2

in .vimrc

Found this at http://linux-journal.blogspot.com/2005/04/fix-vim-backspace-doesnt-work.html

vaichidrewar

Posted 2011-08-30T14:01:13.413

Reputation: 998

This also resolved a similar issue I was having with the cursor keys – Steve Paul – 2016-07-22T17:35:18.300

Thank you, this worked for me -- previously, in Vim, my backspace key was moving back along the line but was not clearing the letters until I started typing. Now it does the 'usual' backspace. – Robert – 2013-03-18T11:50:42.140

4It's great that this answer helped some other users, but in this case it's not the solution to the question since the original question isn't asking about vim. – Kelsin – 2014-03-06T07:34:03.927

12

Worked for me: In the Windows command prompt, type

echo export TERM=cygwin >> C:/cygwin/home/YourUser/.bashrc

This will add it to the .bashrc and everything may work nicely!

Marrciovr

Posted 2011-08-30T14:01:13.413

Reputation: 121

This solved the fact that cygwin64 was ignoring backspaces in commands containing line breaks. Thanks. – suanik – 2019-02-12T09:38:18.057

1

I had the TERM environment variable set to msys via the Windows environment variable settings as suggested on StackOverflow to help with git problems on Windows. Simply resetting it to cygwin in .bashrc didn't help, but removing the TERM entry from the Windows settings did. Thanks for pointing me into the right direction!

– Florian Brucker – 2013-07-26T09:01:24.700

11

I found a solution to a problem that presented like the one above.

Simply run Cygwin setup again and reinstall termcap and terminfo. If you use the search box you can find them quickly. Instead of saying "Keep" for each, click it to make it say "Reinstall". You may have to check the "Hide Obsolete" checkbox for term to appear in the search.

My terminfo folder was entirely missing. No idea why. Hope this helps someone.

SomeCallMeTim

Posted 2011-08-30T14:01:13.413

Reputation: 210

cool , works , but why ?! – Yordan Georgiev – 2015-07-06T21:12:24.177

1I had a custom installed ncurses, that I removed. After removing and reinstalling via cygwin setup.exe I had this problem. I don't want to apply a bandaid by setting TERM variables to something other than what was working before my mishap. Reinstalling terminfo (I couldn't find termcap) worked for me. Thanks! – Kelsin – 2014-03-06T07:32:10.233

5

Edit your c:\cygwin\cygwin.bat

Place this: SET TERM=cygwin

before: bash --login -i

Josef

Posted 2011-08-30T14:01:13.413

Reputation: 51

1The simplest fix by far. Hope there are no side-effects. – RomanSt – 2014-10-02T23:43:31.493

1

When you set the TERM type you are telling the host which TERMCAP to use to draw within the terminal window. Most *NIX hosts don't know what a 'cygwin' termtype is so they don't know how to do onscreen character manipulation such as inserts, deletes, scrolls, font changes, etc.

If you change the TERM variable in CYGWIN before telnet or SSH to a host you will get much better results:

In CYGWIN:

d@test01 ~
$ TERM=ansi;export TERM
$ ssh suntest1

d@suntest1's password:
Sun Microsystems Inc.  SunOS 5.8     Generic patch    October 2001

d   pts/1         test01    Fri   Oct 12  00:15   still logged in
$ echo $TERM
ansi
$_

The host now knows you have an ANSI terminal type and it can use it's ANSI TERMCAP file to tell it how to communicate.

If you can't get that to work and most everything works properly except the backspace, you can reprogram "getty" on the host you connect to to recognize what you want, and here's how (this is the oldest, most common and most universal way of solving backspace/delete issues):

You ssh or telnet to your host and in the host you run the stty command. If you hit the "BACKSPACE" key and it does not go backward it's because the terminal is probably looking for a different character based on the TERM type. Rather than dig through all of that you can manually set the backspace definition at the CLI or in your .profile, .bashrc, or .bash-profile file in your $HOME directory as you desire or based on the flavor of *NIX you are using.

So if you press ^H (that's CONTROL-H) and your key backs up but you hit the BACKSPACE key and it does not try using stty as follows:

stty erase \*<HIT YOUR BACKSPACE KEY HERE>*[ENTER]

Most of the time it will look like this:

stty erase \^?[ENTER]

The '\' tells it that the next character is going to be a non-printable control-character and to accept it, not "interpret" it.

Once you press [ENTER] you should be able to press your [BACKSPACE] key and have it backspace/delete whatever you typed.

You can set this in your shell.

Now, if you still use VI, sometimes the translation doesn't work and you have to actually type ^H in vi, but that's OK.

You could have said:

stty erase k[ENTER]

and it literally would have translated 'k' into the erase/delete character..

-D

TekOps

Posted 2011-08-30T14:01:13.413

Reputation: 41

1

Please follow the image below enter image description here

  1. Right-click anywhere in the Cygwin window
  2. Click options
  3. Click the Keys tab
  4. Tick Backarrow sends ^H
  5. Press apply.

This is the only thing that worked for me, especially since if you have to SSH to a server (not all fixes will work) I used to add stty erase ^? to my .bashrc but this only fixed the issue 80% of the time.

Mark

Posted 2011-08-30T14:01:13.413

Reputation: 235

0

Worked for me: In the Windows command prompt, type

(echo; echo "export TERM=cygwin") >> ~/.bash_profile

This will add it to the .bash_profile (not .bashrc, which didn't work for me, and with a leading line break)

bjelli

Posted 2011-08-30T14:01:13.413

Reputation: 101

0

After spending 2 days of time reading stuff online. I found this one that worked for me. I do not know if this case matches every one. But it worked like a charm to me thanks to Yuksel

The problem was with 'termInfo' files, Steps he have suggested

  1. confirm if the problem is terminal related by typing in CygWin Terminal, this should give (ignore the warning)

    less my_session.log

WARNING: terminal is not fully functional

  1. Get the information of 'TermCap' to which path or directory it is related to by typing below code in CygWin Terminal

    infocmp -C

you should either get

infocmp: couldn't open terminfo file /usr/share/terminfo/63/cygwin

Or you might also get something starting with text like 'Reconstructed via infocmp...'

  1. Run the below code in CygWin Terminal to run the diagnostics to get extra details about the path where the files are saved

    cygcheck -s

that should respond you similar to below text

Cygwin Configuration Diagnostics

...

C:/cygwin / system binary,noacl

C:/cygwin/bin /usr/bin system binary,noacl

C:/cygwin/lib /usr/lib system binary,noacl

C:\cygwin\etc\terminfo /usr/share/terminfo system binary,noacl

cygdrive prefix /cygdrive user binary, noacl, posix=0, auto

...

  1. check out for line similar to

C:\cygwin\etc\terminfo /usr/share/terminfo system binary,noacl

from the output, you got from the 3rd step. now copy all the files and folders that exist inside /usr/share/terminfo to the folder C:\cygwin\etc\terminfo - NOTE: this folder might be different from yours depending on the installation

yellowandred

Posted 2011-08-30T14:01:13.413

Reputation: 111

0

Ok, I had this issue with manually updating a Cygwin install. Anyway I found this post, which lead me to the solution for my install.

The older cygwin had a file /etc/terminfo/c/cygwin, but in the newer cygwin it expected the file to be /etc/terminfo/63/cygwin.

Once I copied the "cygwin" file to this location, the bash shell backspace key worked fine, as did tab and others.

user327463

Posted 2011-08-30T14:01:13.413

Reputation: 9

0

Changing the TERM variable to cygwin and adding SET TERM=cygwin to the .bat file didn't work for me, but I fixed it. Here what I did: In package manager due installation I selected to install xterm: X11 terminal emulator, after installation I added SET TERM=xterm to the .bat file (like proposed above), launched terminal and in Options -> Terminal menu selected Type=xterm, then restarted terminal. Backspace started to work correctly!

Note: if you already installed cygwin – just run installer again and add xterm package.

I'm running:

  • OS = Windows 8 (x64)
  • Cygwin setup.exe version = 2.850 (x64)
  • Mitty version = 1.2-beta1 (x86_64-pc-cygwin)

Argon

Posted 2011-08-30T14:01:13.413

Reputation: 1

0

I agree with all the answers here. But there is a far simpler way found here: http://lifepluslinux.blogspot.in/2014/08/backspace-doesnt-work-in-vim-on-cygwin.html

2991ambusher

Posted 2011-08-30T14:01:13.413

Reputation: 145

-1

Never experienced your problem. Try to install the Terminal Emulator Mintty (http://code.google.com/p/mintty/).

It's available through the Cygwin installer. Best Terminal for cygwin.

Luciano Fiandesio

Posted 2011-08-30T14:01:13.413

Reputation: 117

-1 for recommending something without obvious connection to the reason of a problem you never experienced. That is of no help, only noise and distraction. – trapicki – 2017-01-09T12:26:44.493

This did not help. – user620189 – 2011-08-30T14:45:46.983

Even am stuck on the same issue and from minty also backspace functionality is not working. I get space when i hit backspace on both minty terminal as well as cygwin terminal – Rachel – 2011-12-09T17:03:43.233

@Rachel Did you ever resolve this? I'm seeing the same issue with a fresh Cygwin install. :( – SomeCallMeTim – 2012-03-19T22:31:22.300

@SomeCallMeTim: I was able to fix this issue by using Minty, cygwin behaves in very wierd manner at times. – Rachel – 2012-03-20T13:33:09.050

@Rachel Thanks, though I found out that my problem was that the Cygwin install missed some important files (like /usr/lib/terminfo). I don't know why they were missing; found someone else with that issue, went into setup and told terminfo and termcap to reinstall, and everything worked. – SomeCallMeTim – 2012-03-27T22:39:15.503

@SomeCallMeTim: Am glad that you were able to solve the issue... – Rachel – 2012-03-28T15:00:52.733