emacs backspace question

Nerius Landys nlandys at gmail.com
Thu Mar 24 21:55:50 UTC 2011


> I've read a lot on the internet regarding the use of the backspace key in
> emacs, but the proposed solutions don't seem to be working for me.
>
> I just installed FreeBSD 8.1 in Virtualbox and installed emacs 23.2.1 by
> means of the package installer.  Everything in emacs works great except the
> backspace key, which deletes forward instead of back like it should.  I've
> found a lot of different things on the internet about it:
>
> * switched to bash instead of csh - didn't fix it, but I like bash better
> * M-x normal-erase-is-backspace-mode -toggling it once makes my backspace
> bring up the "help" command; toggling it again changes it back
> * different keymaps
>    - I started out using us.iso.kbd (which exhibits the backspace issue, but
> other keys are right)
>    - I tried us.emacs.kbd - backspace works right, but many other keys are
> mapped wrong (even letters and numbers)
>    - I tried us.unix.kbd - backspace doesn't work right and neither do my
> control keys
>
> I also just noticed that when on the command line itself (outside of emacs)
> backspace deletes backward as it should, but so does delete!
>
> Is this something weird with virtualbox, or am I doing something wrong?

You have just discovered what is in my opinion a can of worms with no
clear solution.  I have struggled with issues such as these before,
and I've managed to solve them more or less.

Are you using emacs in a terminal window?  (As opposed to with an X
server.)  I'm assuming yes.
Are you accessing your computer directly through the console or
through an xterm and SSH, for example?  Questions such as those are
important to fully diagnose and fix the problem.  You want to do an
"echo $TERM" before you start diagnosing problems such as these.

If you are using bash, you can do a "man bash" and look at the part
that describes ~/.inputrc and/or READLINE.  You may want to create an
~/.inputrc file and add stuff to it to resolve the backspace/delete
issues that you are having.  For example, I have the following in my
~/.inputrc because I do use bash occasionally:

  $if term=cons25
    "\x7f": delete-char
  $else
    $if term=xterm
      "\x1b\x5b\x35\x43": forward-word
      "\x1b\x5b\x31\x3b\x35\x43": forward-word
      "\x1b\x5b\x35\x44": backward-word
      "\x1b\x5b\x31\x3b\x35\x44": backward-word
    $endif
  $endif

"cons25" is the native FreeBSD console (like when you're physically at
the computer console) and xterm is of course xterm.  (Side note: Why
in the heck on my 9.0-CURRENT system the system console says the TERM
is xterm?)

As far as how I came up with the strings such as "\x1b\x5b\x35\x43",
you can use a command such as "xxd" which comes with the vim
package/port to tell you what bytes are being sent when you press a
certain key.

If you want to fix your csh shell too, you may consider editing your
~/.cshrc file.  Here is my complete ~/.cshrc, and note the stuff at
the bottom with the key bindings:

  setenv  EDITOR  vi
  setenv  PAGER   less
  if ($?prompt) then
          # An interactive shell -- set some stuff up
          set prompt = "`whoami`@`/bin/hostname -s`> "
          set filec
          set history = 2000
          set savehist = 2000
          set mail = (/var/mail/$USER)
          if ( $?tcsh ) then
                  bindkey "^W" backward-delete-word
                  bindkey -k up history-search-backward
                  bindkey -k down history-search-forward
                  if ("$TERM" == "cons25") then
                          bindkey "^?" delete-char
                  else if ("$TERM" == "linux") then
                          bindkey "^[[3~" delete-char
                  else if ("$TERM" == "xterm") then
                          bindkey "^[[3~" delete-char
                          bindkey "^[[5C" forward-word
                          bindkey "^[[1;5C" forward-word
                          bindkey "^[[5D" backward-word
                          bindkey "^[[1;5D" backward-word
                          bindkey "\303\277" backward-delete-word
                  endif
          endif
  endif


By the way I have a 9.0 CURRENT box here at my desk, and I've compiled
emacs-nox11 port, and I'm at the system console (meaning I'm
physically at the console).  I am using /bin/tcsh as my shell.  I have
no modifications to any of my dotfiles, they are all stock.  In emacs,
I'm able to use Backspace and Delete just as expected.

Maybe you should try setting your default shell to /bin/tcsh, if it
isn't already.  If you're on a mission critical system you want your
default shell to be part of the base system (as opposed to being a
port), and the only clear choice for that is /bin/tcsh.  Besides it's
the default root shell too.

Also, if you are looking for a superior shell from ports you might try
zsh.  It's the best in my opinion.


More information about the freebsd-questions mailing list