I'm on Solaris 10 and by default vi version SVR4.0, Solaris 2.5.0 is installed.

The system was set up so that when I ssh to it Control+H does backspace, and backspace outputs ^?

I added stty erase '^?' into .profile so that in the terminal the backspace key works correctly now. However when I use vi it still is outputting the ^? character.

Normally I would type :set nocompatible to fix this but it gives me

compatible: No such option - 'set all' gives all option values

set all gives me

noautoindent            nomodelines                     noshowmode
autoprint               nonumber                        noslowopen
noautowrite             nonovice                        tabstop=8
nobeautify              nooptimize                      taglength=0
directory=/var/tmp      paragraphs=IPLPPPQPP LIpplpipnpptags=tags /usr/lib/tags
noedcompatible          prompt                          tagstack
noerrorbells            noreadonly                      term=xterm
noexrc                  redraw                          noterse
flash                   remap                           timeout
hardtabs=8              report=5                        ttytype=xterm
noignorecase            scroll=33                       warn
nolisp                  sections=NHSHH HUuhsh+c         window=66
nolist                  shell=/bin/ksh                  wrapscan
magic                   shiftwidth=8                    wrapmargin=0
mesg                    noshowmatch                     nowriteany

I'm guessing that this version of vi is too old and that I need either a newer version or vim if I want to use set nocompatible, but I'm wondering is there another way to get vi to use backspace for backspacing without having to load vim?

  • check your terminal settings. vi will use your TERM type, and use the termcap database to determine what the default capabilities of your terminal are. If you are using putty, you can change edit the ssh profile for that server and set it to send Control-? for backspace, instead of Control-H. – Tim Kennedy Oct 24 '11 at 18:04
  • tried dtterm, xtermc, vt320 and all the other ones i could find. terminfo has a man page but the command is not found. backspace works fine at the command prompt, just not in vi – cwd Oct 24 '11 at 18:49
  • try setting :map! ^? ^H in your .exrc file. note that ^? is not simply a ^ (shift+6) and a question mark, it's character created by pressing control+v control+shift+backspace, and ^H is created by pressing control+v control+h. – Tim Kennedy Oct 25 '11 at 5:07
  • that did it, thanks! want to post this below? btw unfortunately the arrow keys still produce ACDB. – cwd Oct 25 '11 at 5:51
  • posted below, with the entries to map the arrow keys as a bonus. :) – Tim Kennedy Oct 25 '11 at 12:52

ok. so we solved the backspace key not working.

by adding

:map! ^? ^H

to your .exrc file. to map the arrow keys in a similar manner, you can add the following to the same .exrc file.

:map! ^[OA ^[ka
:map! ^[OB ^[ja
:map! ^[OC ^[la
:map! ^[OD ^[ha

Keep in mind that all of these 'escape codes' are created not by simply typing shift+6 for the '^' character, but by pressing the following keys:

backspace & delete:

  • ^? = control + v+delete
  • ^H = control + v+control + h

up arrow:

  • ^[OA = control + v+up arrow
  • ^[ka = control + v+esc+k+a

down arrow:

  • ^[OB = control + v+down arrow
  • ^[ja = control + v+esc+j+a

right arrow:

  • ^[OC = control + v+right arrow
  • ^[la = control + v+esc+l+a

left arrow:

  • ^[OD = control + v+left arrow
  • ^[ha = control + v+esc+h+a

Any comment lines in your .exrc file must be marked by ", rather than #. And you can't leave any blank lines in your .exrc file, otherwise that first blank line is where your .exrc will stop being processed.

Once these are in place, vi will start to feel a bit more like it was designed for use by humans. :)

for an example of how powerful the .exrc file is, check out this .exrc example by Dave Capella.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.