29

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.

  • Can you give more details of how you installed and invoked Cygwin, and where exactly the backspace key fails to work? – ak2 Aug 30 '11 at 14:40
  • 1
    I'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 Aug 30 '11 at 17:57
  • What sort of keyboard do you have? US, UK etc. – pjc50 Nov 7 '11 at 10:26
  • 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 Mar 19 '12 at 22:30

12 Answers 12

34

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

| improve this answer | |
  • 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 Mar 18 '13 at 11:50
  • 4
    It'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 Mar 6 '14 at 7:34
  • This also resolved a similar issue I was having with the cursor keys – Steve Paul Jul 22 '16 at 17:35
13

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!

| improve this answer | |
  • 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 Jul 26 '13 at 9:01
  • This solved the fact that cygwin64 was ignoring backspaces in commands containing line breaks. Thanks. – suanik Feb 12 '19 at 9:38
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.

| improve this answer | |
  • 1
    I 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 Mar 6 '14 at 7:32
  • cool , works , but why ?! – Yordan Georgiev Jul 6 '15 at 21:12
5

Edit your c:\cygwin\cygwin.bat

Place this: SET TERM=cygwin

before: bash --login -i

| improve this answer | |
  • 1
    The simplest fix by far. Hope there are no side-effects. – RomanSt Oct 2 '14 at 23:43
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

| improve this answer | |
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.

| improve this answer | |
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.

| improve this answer | |
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)
| improve this answer | |
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

| improve this answer | |
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)

| improve this answer | |
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

| improve this answer | |
-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.

| improve this answer | |
  • This did not help. – user620189 Aug 30 '11 at 14:45
  • 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 Dec 9 '11 at 17:03
  • @Rachel Did you ever resolve this? I'm seeing the same issue with a fresh Cygwin install. :( – SomeCallMeTim Mar 19 '12 at 22:31
  • @SomeCallMeTim: I was able to fix this issue by using Minty, cygwin behaves in very wierd manner at times. – Rachel Mar 20 '12 at 13:33
  • @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 Mar 27 '12 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.