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.
6 Answers
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 ofvim
from the commandline, wherevi
is only a sym-link tovim
, in which case vim is opened in vi mode. You can check this with:set compatible?
.As mentioned by the previous answer, the effect of the backspace becomes only visible after leaving in
insert mode
whenset 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?
.

- 5,631

- 357
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!

- 171
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.

- 21,510
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.

- 141
- 4
Creating a .vimrc in my home directory that contains only
set nocp
fixed my problem with backspace not removing the character from the screen Dick S.
vim
. – Stéphane Chazelas May 16 '13 at 19:27