backspace in insert mode not erasing characters

  1. Checkout whether your are actually using plain vi via

    $ vi --version | head -n 1

    This gives on my machine (Debian 7)

    VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Feb 10 2013 02:27:59)

    vim can be made to behave more like vi. This can be done by giving the command vi instead of vim from the commandline, where vi is only a sym-link to vim, in which case vim is opened in vi mode. You can check this with :set compatible?.

  2. As mentioned by the previous answer, the effect of the backspace becomes only visible after leaving in insert mode when set compatible is enabled.

Note: In vi-compatible mode, you cannot backspace over text which was previously entered (before entered insert mode) or eol's or indentation in insert mode. see :help 'bs'

    'backspace' 'bs'        string  (default "")
                            global
                            {not in Vi}
    Influences the working of <BS>, <Del>, CTRL-W and CTRL-U in Insert
    mode.  This is a list of items, separated by commas.  Each item allows
    a way to backspace over something:
    value   effect
    indent  allow backspacing over autoindent
    eol     allow backspacing over line breaks (join lines)
    start   allow backspacing over the start of insert; CTRL-W and CTRL-U
            stop once at the start of insert.

    When the value is empty, Vi compatible backspacing is used.
    For backwards compatibility with version 5.4 and earlier:
    value   effect
      0     same as ":set backspace=" (Vi compatible)
      1     same as ":set backspace=indent,eol"
      2     same as ":set backspace=indent,eol,start"

Try out the different settings to understand their meaning: Enter characters/line breaks and indentation in insert mode, exit and reenter insert mode and then try backspacing.

Users who are not familiar with vi behaviour and don't insist on using plain vi (not recommened anyway) should :set backspace=indent,eol,start. Afaik on Debian there is usually a system-wide config file installed with this setting.

You can get the current setting via :set bs?.


Sometimes the vi command is an alias for vim and when called as vi enables its vi-mode.

Even in traditional mode backspace is deleting the character, but does not display it as deleted immediately. (After pressing ESC the characters are gone.)

Guess you have to choose between using vi which comes with the described behavior or using vim which is able to do it the way you expect it.


Create a new file in the user home directory called .vimrc if it's not already there. Here we'll create and edit at the same time with vi

sudo vi ~/.vimrc

Add the following commands, which include turning off compatibility mode and backspace key erase functionality:

set nocp
set backspace=indent,eol,start

Save and exit file using

:wq

Turning off compatibility mode allows the use of arrow keys us old vi guys are used to.

Since we sudo'd when creating the file, the ownership of the file will probably be root. You can chown the file to the user.

In my case this was for a raspberry pi, so the user and group is pi:

chown pi:pi ~/.vimrc

Now fire up vi again and enjoy!

Tags:

Vi