[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: vi: backspace and delete key

On Fri, Aug 31, 2001 at 12:49:53AM -0400, Steve Dondley wrote:
| I've heard of problems with emacs and the backspace and delete key not
| working properly.  Now I'm wondering what the correct behavior for vi is.
| My keys seem to be acting a funny.

The biggest problem with backspace vs. delete was caused by some
terminal manufacturer many years ago.

The button on your keyboard in the upper right corner that usually has
the glyphs "backspace" on it originally sent ASCII character 127 to
the host.  This was with vt100's or something "original" like that.
IIRC they don't even have a key labeled "delete".

In the ASCII table, however, you will notice a character with the name
"BS" (backspace) but it has the value 8.  Some manufacturer at one
time decided that the button labeled "backspace" on your keyboard
should send the ASCII backspace character (8) and made the delete key
send 127 (which is labeled DEL in man ascii on at least some systems).

The BS character also has the representation ^H, and the DEL character
has the representation ^?.

If you look at your terminal and type "stty -a" you will see which
character has the "erase" function (commonly known as "backspace").
Then you can check your terminal emulator settings to see character it
sends when you press the backspace and delete keys.  (At a shell
simply type ^V[backspace] -- that is Ctrl-V then Backspace -- and you
will see either ^H or ^?)

As you can see this is a big mess, but you just need to make sure that
all your terminals and shells agree on what the backspace and delete
buttons on your keyboard mean.

(Somewhere there is a web page that explains all this will all the
right details regarding manufacturers, etc)

| Backspace:  Behaves the same way as left arrow key but it keeps you in edit
| mode.
| Delete: Very weird behavior...pressing it once will capitalize the previous
| letter.  The following keypresses  delete the letter to the right of the
| cursor but you also get bounced out of edit mode.
| This is ridiculous.  There are all these different versions of vi
| (apparently I have nvi) and I don't know what to believe.  Some site say
| backspace does one thing and others say it does another.
| Can someone shed some light on this craziness?  Figuring all these minor
| details out is getting extremely irritating to say the least.

Now for dealing with vi.  In original vi (/usr/bin/vi on my school's
Solaris system) the backspace button would only work in insert mode,
and it would only backspace (delete characters to the left of the
cursos) up to the point where you entered insert mode.  In addition it
would not clear the characters from the screen unless you switched to
command mode or requested a redraw with ^L.  Perhaps nvi works that
way too.  

I don't know what vim's default handling of backspace and delete is,
but I have

" allows for backspace of items not inserted in this "insert session"
set backspace=2 

in my .vimrc so that I can backspace through the entire buffer.  The
backspace deletes the character to the left of the cursor and the
delete deletes the character to the right.  It is completely intuitive
and expected.  Also, vim clears the characters from the screen when
you backspace over them.


Reply to: