Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am new to vi, actually I have started learning vi from today and I have got stuck at the behavior of the backspace key. Actually when I fired up vi on my Ubuntu 12.04 for the first time my backspace key was working normally but after that it has started behaving strangely. Whenever I press the backspace in the insert mode it just moves one place to the left instead of erasing the character. How can I get back the default backspace functionality? Please note that I don't want to install vim or set nocompatibilty.

share|improve this question
5  
That's the traditional vi behaviour. If you've got the option to set nocompatibility, then you're already using vim. –  Stéphane Chazelas May 16 '13 at 19:27
    
I am not aware that vi is installed on Ubuntu. vi in Linux world in my experience is just a symbolic link to vim. If you want to learn real vi either install nvi or hairloom project vi. –  Predrag Punosevac May 18 '13 at 2:11

3 Answers 3

up vote 3 down vote accepted

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.

share|improve this answer

I think the best way would be to look at VI/VIM cheatsheet : http://www.viemu.com/vi-vim-cheat-sheet.gif

Enter normal mode (ESC) and then SHIFT + X.

share|improve this answer
  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?.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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