# stty erase ^? doesn't work



## krnlpk (Sep 12, 2010)

I'm trying to use 
	
	



```
stty erase "^?"
```
 to change the behavior of the delete key. 
Both Backspace and Del are working as backspace, and I find this quite annoying.
But, after executing stty as written above, I just get a backspace command that prints "^H" instead that "^h", and a del key that acts as backspace. If I use csh instead of bash, simply nothing happens. What can I do?


----------



## wblock@ (Sep 12, 2010)

What shell are you using?


----------



## krnlpk (Sep 12, 2010)

wblock said:
			
		

> What shell are you using?



Bash, at the moment, but either on csh stty seems to not work.


----------



## wblock@ (Sep 12, 2010)

krnlpk said:
			
		

> Bash, at the moment, but either on csh stty seems to not work.



It may also depend on your terminal.  For instance, xfce's Terminal has Edit/Preferences/Advanced "Backspace generates" options.

Otherwise, Consistent BackSpace and Delete Configuration is useful.


----------



## krnlpk (Sep 12, 2010)

stty doesn't work. Either bind. If I try to set something, the only thing I succeed in is corrupting backspace.


----------



## Beastie (Sep 12, 2010)

For csh, add *bindkey ^[[3~ delete-char* to .cshrc.


----------



## krnlpk (Sep 12, 2010)

Beastie said:
			
		

> For csh, add *bindkey ^[[3~ delete-char* to .cshrc.



It doesn't work. My shell (bash, csh, whatever) refuses to bind anything else than ^H to delete key.


----------



## wblock@ (Sep 12, 2010)

Oops--I meant to say "Delete key generates" above, about Terminal.  What terminal are you using?


----------



## krnlpk (Sep 12, 2010)

wblock said:
			
		

> Oops--I meant to say "Delete key generates" above, about Terminal.  What terminal are you using?



None. I'm using real ttys, I've not installed X.


----------



## AndyUKG (Sep 13, 2010)

krnlpk said:
			
		

> I'm trying to use
> 
> 
> 
> ...



Firstly, if you currently have multiple keys working as backspace, what makes you think setting another (or resetting one of the existing keys) will stop one or other from being backspace? Maybe it will, I dont have mutiple keys working as backspace to test against but not convinced.
Secondly, are you using the carrot key "^" when you enter the stty erase command? This needs to be entered not using the carrot key as you find it on they keyboard, but simply by pressing the backspace or whichever key you want. You may have to first type Ctrl+v then type the key you are after, Ctrl+v escapes special keys.
IE on one of my systems backspace is "^?", which is written in a terminal window if I first type Ctrl+v then backspace...

thanks Andy.


----------



## krnlpk (Sep 14, 2010)

Even if I try to use ctrl-v, every tentative to set an alternative behavior to del key fails.


----------



## SirDice (Sep 14, 2010)

Remove the quotes.

`# stty erase ^?`

Instead of typing shift-6 (on a US keyboard) and ? press the backspace key.

Works as it should. But you should not need to change it. It's set correctly by default. Same for home and end keys.


----------



## krnlpk (Sep 14, 2010)

SirDice said:
			
		

> Remove the quotes.
> 
> `# stty erase ^?`
> 
> ...



I've already done it, it just do nothing!
When I press backspace I expect that the character on the left of the cursor will be deleted, and the right one when I press Del. In both cases, the left char is the one to be deleted, even if I try to set other values for erase or erase2, the only results I managed to get are a corrupted backspace key and a delete key that works as before.
I don't know why, nobody of you have ever get this behavior before?


----------



## SirDice (Sep 14, 2010)

The delete key doesn't do what you expect it to do. In traditional unix the delete key acted as backspace (backspace didn't exist).

Learn to use ctrl-d.


----------



## krnlpk (Sep 14, 2010)

SirDice said:
			
		

> The delete key doesn't do what you expect it to do. In traditional unix the delete key acted as backspace (backspace didn't exist).
> 
> Learn to use ctrl-d.



So, there's no way to change its behavior?


----------



## SirDice (Sep 14, 2010)

Beastie's solution seems to work. At least for tcsh.


----------



## krnlpk (Sep 14, 2010)

SirDice said:
			
		

> Beastie's solution seems to work. At least for tcsh.


I've already tried it but it haven't worked for me. Thanks a lot to everybody for the patience


----------



## Nicola Mingotti (Mar 17, 2018)

I stumbled across this old post because of a similar problem I had running "mg" and "Emacs" in terminals /dev/ttyvXX (not in X), where the Backspace was not doing its job.

I add stuff here for reference to people how may find a similar issue in future.

0] run `tty` to understand the kind of terminal you are using.
If you are our of X most probably you are dealing with "virtual terminals" so
in output you will see a file with a name like /dev/ttyvXX. The description below applies only in this case.

1] Analyze the keycode you are receiving from the keyboard with `kbdscan`. This is as helpful as `xev` in X !

2] Forget `kbdcontrol`, that is for the system console only, not virtual termianals.

3] If necessay, tell explicitely in /etc/rc.conf the keymap you are using, .e.g

```
keymap="us"
```
that refers to the file /usr/share/vt/keymaps/us.kbd.

4] Modify e.g. /usr/share/vt/keymaps/us.kbd to what you want and check if it is working with `kbdmap`; toggle the selected keyaboard in and out of your modified map to force the keymap changes to be loaded.

5] You may use this trivial script to see what ascii codes are arriving to your
shell

```
ruby24 -e 'require "io/console"; c = STDIN.getch; puts "ascii #{c.ord} --- char #{c}" '
```

6] Once you know:
--] the keyboad signal code arriving
--] the keymap used for translation: keyboardCode --> asciiCode
--] the ascii code arriving to your shell after translation
=> You are ready to take actions.

In my case I needed to configure "mg" because Backspace and the "mg"
sequence "C-h" were bound to the same ascii code and "C-h" (mg help function was taking precedence).


----------

