# vi editor



## neo36 (Jul 7, 2002)

does anybody know how you can delete characters when using the vi editor? the backspace key doesn't work.....

thx!


----------



## deraven (Jul 8, 2002)

vi is a serious text editor with incredible capabilities, but if you're not familiar with it and won't be doing a great deal of editing, I'd suggest sticking with pico. 

To answer your question:

1. Hit "Esc" to make sure you're no longer in insert or some other mode
2. Move the cursor to the character you'd like to delete
3. Hit "x" to delete a single character

If you want to delete a whole line, press "d" twice.

There are a host of other deletion commands, but those are two easy ones.

If you want to learn more about the rest, check out the vi man page.

Also, there are some good one-page vi "cheat-sheets" online that you can always print out and keep handy until you've got it all down.

Enjoy!


----------



## hazmat (Jul 8, 2002)

If you want to delete back, like backspace would do, use 'X' (capital).


----------



## neo36 (Jul 8, 2002)

thanks, folks!

your tips helped. but does anybody actually know why the BACKSPACE key doesnt work with vi? i think it works when using linux...


greetz!


----------



## hazmat (Jul 8, 2002)

> _Originally posted by neo36 _
> *thanks, folks!
> 
> your tips helped. but does anybody actually know why the BACKSPACE key doesnt work with vi? i think it works when using linux...
> *



My guess is that standard vi doesn't support that in insert mode, or at least you have to make some setting for it.  I just tried it under both OS X and Solaris and both act this way.  The reason Linux would do it is because probably no Linux distribution has standard vi, but rather a clone, like nvi, vim, etc.  My personal favorite is vim.  I would recommend installing that.  I'm sure you can find a package somewhere, but the source should build fine.


----------



## BSDimwit (Jul 8, 2002)

vi has been around since the dawn of epoch time.  It was one of the first editors used by UNIX hackers from days gone by.  While it has been updated over the years to work on every flavor of *NIX out there, a look at its origins explain alot when you consider how unintuitive it is.

The first unix terminals didn't have 104 key keyboards.  They were teletype machines that had paper coming out of the top instead of a monitor.  Because of this limitation, a means had to be devised for it do all of the stuff that any modern editor needs to be able to do.  Hence the Esc D commands for deleting.  

vi is still around today because of its portablility.  As I said, it runs on every *NIX out there.  It has been upgraded over the years to add features and power, but its stays close to its roots in function to keep its portability intact.  Unless you are a glutton for punishment, or have been weened on vi, I would defininately recommend the use of pico or emacs, over vi.  While its power is undisputed, its ease of use leave much to be desired.  All unix hackers should have a cursory understanding of vi as a just in case option when pico or emacs isn't loaded on the machine in question, but when given other options, a beginner should look elsewhere for his/her editing needs.

Oh and the answer you are looking for probably has something to do with keyboard mapping and the stty command in unix.  Linux probably has the backspace key set to ctrl-h, whereas apple and darwin might not.


----------



## neo36 (Jul 8, 2002)

i'll stick with the vi i have, i was just curious...   
thx anyway!


----------



## btoneill (Jul 8, 2002)

Actually using standard vi for me on Solaris has both a working backspace and delete keys while in insert mode. I've never had any problem with this not working on any OS. And this is using the standard vi, I personally abhor nvi/vim/etc.

From the vi manpage (on Solaris, don't have OS X at work):
Corrections during insert
     ^H    erase last character (backspace)

I'll take a look at this on my box at home later today if I don't see a resolution by then.

Brian


----------



## Eckhart (Jul 14, 2002)

You explained it all, here are just a few remarks. It is correct, Vi has originally been ex (which ist the command line interface) and ex has been aroung since the early seventies, when there were no backspace keys.

Linux distributions nowadays mostly replaced the vi with vim (Vi Improved) which has several features, colors, backspace-support etc built-in. In contrast, Freebsd uses the nvi which does not broadly differ from the original vi. What I have also seen, is that Linux distribution automatically install huge .exrc files (config files) in your home directory. Open one of these files and you will see a lot of key mappings. To create your own map, open vi and type ':map ^? x'. That'd be your case. '^?' is the sequence for the backspace key. That sequence might vary from machine to machine. You get by typing CTRL-V and then BACKSPACE. You could also write the given line into your personal .exrc file.

Another option would be to download a sample .exrc file, copy it to $HOME and adjust it to suit your needs. My advice anyway: Don't rely on an .exrc configuration,  since it is specific and you will not find the same configuration on other boxes.


----------

