Solved Getting delete to remove character under cursor

  • Thread starter Deleted member 9563
  • Start date

Deleted member 9563

The problem of getting keys like end, home, backspace and delete to perform specific actions is apparently a common one, judging by the number of posts I've seen on the topic. I've tried various things over the years and have probably spend time adding up to days on this problem. I am posting here in case somebody has found a solution now, but mostly to document this extraordinary situation.

Current Environment:
KDE Development Platform: 4.14.10
Konsole: 2.14.2
Editor ne

Backspace works for me now, and I finally got home and end to do as expected instead of just showing tildes (~) by putting this in the .cshrc
if ($term == "xterm" || $term == "vt100" \
            || $term == "vt102" || $term !~ "con*") then
          # bind keypad keys for console, vt100, vt102, xterm
          bindkey "\e[1~" beginning-of-line  # Home
          bindkey "\e[7~" beginning-of-line  # Home rxvt
          bindkey "\e[2~" overwrite-mode     # Ins
          bindkey "\e[3~" delete-char        # Delete
          bindkey "\e[4~" end-of-line        # End
          bindkey "\e[8~" end-of-line        # End rxvt

It seems, however, that the delete key is resistant to any changes in behaviour. It insists on working the same as the backspace key. There is a comprehensive list of suggestions on this site, but none work in my environment.

I've looked at what seems like every conceivable configuration file that could have anything remotely to do with keys and terminals, but to no avail. If somebody has had this problem too, I'd be interesting in hearing some of the things you've tried. Perhaps something will work for me even if it didn't for you.
Should be able to delete anything from a shell if you wrap it in "filename" or 'filename'

rm "adf sef # adsf efw"
should work to remove any filename

As far as termcap what it looks like you are after... I do not know the answer for that.
Thanks Robbykaty. I can delete anything. ;) The system is quite functional. What I want to do is have the character under the cursor deleted when I hit the delete key - in the same way that the backspace key deletes the character to the left of the cursor. It does this in tty very nicely.
It works in the where does it not work? In x11/xfce4-terminal, there is an option to set which character is generated when backspace is pressed. I have that set to Ctrl-H.
In .cshrc, I have these, which ought to be neatened and organized better:
  # bindkey "^?" delete-char
  bindkey "\e[1~" beginning-of-line
  # bindkey "\e[2~" overwrite-mode
  bindkey "\e[3~" delete-char
  # bindkey "\e[4~" end-of-line
  # use ctrl-left and ctrl-right to jump by word
  bindkey "\e[1;5D" vi-word-back
  bindkey "\e[1;5C" vi-word-fwd

  switch ( $tty )
    case "ttyv*":
      # a real console
      bindkey "^?" delete-char
      # need "set rebinddelete" in .nanorc, also
      # an xterm

  stty erase "^H"
  if ( $?tcsh ) then
    bindkey "^W" backward-delete-word
    bindkey -k up history-search-backward
    bindkey -k down history-search-forward
Thanks wblock@ I'll investigate that further.

Backspace works, as does Home and End, it is only the Del which does not work.
I just tested on another system with the same OS etc, but where I have not played with anything. Same story there. It seems that "~" is the default result of hitting the "del" key, both in the terminal and on tty. There is a configuration item in Konsole on KDE (both of which I use) but I cannot figure it out as it is some strange GUI thingie without reference in the Konsole manual. I'd be happy to change some of my habits, but feel that the real problem is deeper in the system and if I could fix that, all else would be fine.

The most important thing is that keys work as I expect in my editor, and that is indeed the case now. The command line thing (Konsole and tty) are just a nuisance.
It looks like my editor (ne) only works in two of the three choices in the Konsole config:

 default-XFree4 = tty ok; term ok;    ne, no backspace
 Linux console = tty ok; term del works as back; ne, ok 
 Solaris console = tty ok; term del works as back: ne, ok

Perhaps Konsole will not work for me and I have to explore other options. I'm not too fussy as long as I have green letters on a black background so I can read it with my old eyes. Perhaps another one like Xterm can be made readable. Out of the box xterm is completely useless to me. The obvious option is to change the keybindings in the ne configuration file. I've tried that but it only takes key number options and (despite making sure that they are correct for this terminal), doesn't work.

EDIT: I've done some research and decided to stay with Konsole. That means that the only options are the "linux console" or "Solaris console" choices in Konsole as the "XFree4" provides no backspace in my editor. If it is possible to change the default behaviour of the delete key under those circumstances, it would be great. After hours of research, I have no idea how. I'll just have to be prepared to not have a delete key for the command line - as I have it now. That's not the worst thing since I type very carefully when entering commands there. I had hoped this could be fixed, but I doubt it now. The delete command isn't even included in many key configuration files.
As there's a lot of differences in behavior I've learned to use the "traditional" keys, CTRL-D; delete character, CTRL-A; beginning of the line; CTRL-E; end of the line. Those pretty much work everywhere, even on Cisco devices.

The backspace key depends on if it's ^H or ^?. You can usually switch between the two with stty erase ^H or stty erase ^?.
The backspace key depends on if it's ^H or ^?. You can usually switch between the two with stty erase ^H or stty erase ^?.

Thanks. That puts me one step further ahead. :)

Interesting, stty erase ^H has the effect of making the home and end keys work (and without the tilde replacement) and leaving the backspace working normally. It has no effect on delete.

% stty erase ^?
stty: illegal option -- Programs
usage: stty [-a | -e | -g] [-f file] [arguments]

It looks like Konsole (KDE) is not going to allow the delete character unless I use the default (Xfree 4) profile which screws up my editor. I'm looking into how that might be edited in the key bindings profile but it's a complex GUI and although I know where, I don't know how. I have yet to find anybody in the KDE community who does, but perhaps some day.

PS: Yes, I should probably switch away from KDE since it keeps moving toward becoming some sort of OS, but I've been using it for years because of the configuration control, and apart from this issue Konsole really suits me.
% stty erase ^?
stty: illegal option -- Programs
usage: stty [-a | -e | -g] [-f file] [arguments]
You probably need to escape the ?, the shell may treat it as a glob. stty erase ^\?

I usually use CTRL-V, then press the backspace key. The CTRL-V will tell the shell to take the next key 'literally'. The CTRL-V trick should work for those bindkey commands as well.
Thanks, but that didn't work. The delete still removes characters to the left like the backspace, instead of deleting the character under the cursor.
This one works for me (on (t)csh):
bindkey "^[[3~" delete-char
I already have that in .cshrc Theoretically it should go into the Konsole key bindings, but putting it there makes the delete key just print it verbatim, which is certainly funny but entertainment only goes so far. :)
I know PuTTY has some options dealing with this, those are under Terminal -> Keyboard. Specifically the 'home' and 'end' keys have two settings, 'standard' and 'rxvt'. I don't use Konsole but it may have something similar. There are also some options for function keys and the keypad. There are standards but the problem is that there are too many standards ;)
Those are my configurations on .cshrc. I have delete and backspace properly working here.

bindkey ";5D"   backward-word
bindkey ";5C"   forward-word
bindkey "^W"    backward-delete-word
bindkey "\e[3~" delete-char
bindkey "\e[5~" history-search-backward
bindkey "\e[6~" history-search-forward
bindkey -k up   history-search-backward
bindkey -k down history-search-forward
Thanks @lebarondemer I'll save that for comparison. I assume you don't use Konsol. The problem I've apparently got is that Konsol doesn't honour all those, and I can't set the delete function in .cshrc.
Thanks @lebarondemer I'll save that for comparison. I assume you don't use Konsol. The problem I've apparently got is that Konsol doesn't honour all those, and I can't set the delete function in .cshrc.
Yes, do not use Konsole on FreeBSD but on Gentoo with bash (Yakuake to be more precise) - at least until the current KDE come to the tree and I make the switch to FreeBSD. :)

My FreeBSD install do not have X.

IIRC Konsole uses some internal configurations for that. The mine one (on Linux) just come with "XFree 4", Linux Console, Solaris Console. I use "XFree 4". You would need to modify or create your one.
IIRC Konsole uses some internal configurations for that. The mine one (on Linux) just come with "XFree 4", Linux Console, Solaris Console. I use "XFree 4". You would need to modify or create your one.
Those are the three profiles that I have too. The XFree 4 profile does not work for my editor. The other two do. However, the question is how to edit those. It is a GUI editing process and changing things there results in garbage. Specifically, If I define the delete key as \e[3~ I get \e[3~ on the command line when I press the delete key. Like I mentioned earlier, that is certainly funny. But I'm tired of laughing, and frankly, had thought that the Konsole developers were beyond playing practical jokes. I'm hoping that some day Konsole will have a man page that includes this particular part of it, or that someone with intimate familiarity will come along and advise me. I'll just wait. Two days work is already too much to get the delete key to work. Perhaps I'll just scrap my HDD and go to punched tape where this particular configuration will be perfect. :)
I never tried editing it indeed, I just assumed it would work as expected. Maybe worth give a try to x11/qterminal from LXQt, or x11/sakura, or x11/guake - I personally prefer the drop down style ones.

Well that does indeed look interesting. A quick try of qtrminal and sakura and they work correctly for me but no backspace in my editor. I have to quit for the night now, so will see if I can fix that tomorrow. Both of those look just great for me and may be useful. Thanks!

My wants for a terminal are actually pretty simple. It must support cut/paste when used in a DE and it must support home end delete and backspace in "normal" ways.
Abandoning KDE Konsole and using QTerminal has solved all my problems and more.

After that last post I removed all my KDE Konsole instances and opened up 7 instances of QTerminal. This has been the situation for three days. During that time I've done all the usual things I do on my desktop and all has been fine. The terminals look very nice are better than what I would have expected even. Not one problem has occurred with them.

I chose the "solaris" emulation (under behavior) and use the .cshrc suggestion from wblock@ in an above post. My editor works as expected, as does plain tty and the QTerminal in KDE. Also logging into a bash shell over SSH works as it should.

One thing is now also extremely noteworthy. I've had problems with KDE's plasma-desktop sometimes freezing and KDE apps opening with a blank window or occasionally not at all. It was necessary to kill and restart plasma-desktop. This has been with me since the beginning of FreeBSD 10.0-RELEASE, but is now no longer present. It seems then, that there is a bug in Konsole which is causing trouble with plasma-desktop. I can't pin it down enough to make a bug report, but it is clearly a serious problem with Konsole, which also has had a couple of other glitches like freezing every few weeks - probably related to SSH connections. That is also not a problem any more.

lebarondemerde you must know that your suggestion has been a great success for me, and as an aside, I'm also using a dropdown version in the mix. :)