tl;dr: Add this to your vimrc to make the backspace work like in most other programs:
Though the default behaviour may be surprising, the backspace "not working" can be considered a feature; it can prevents you from accidentally removing indentation, and from removing too much text by restricting it to the current line and/or the start of the insert.
:help 'backspace' tells us:
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:
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.
So what do these values mean exactly?
Vim adds automatic indentation for many filetypes; by default, you're not
allowed to backspace over this; the rules of what is considered to be
'autoindentation' are somewhat subtle, for example, if we would type this (where
█ is the cursor):
if :; then
Backspacing won't work.
But if we would then add a command and the
fi, and go back up, we are
allowed to remove the indentation:
if :; then
This is because in the first example, Vim determined it should add 1 level of indentation when you pressed Enter; but in the second example, Vim didn't autoindent anything, it's just Tab characters or a few spaces.
This should be the most obvious, pressing Backspace also removes EOL
\r\n); if disabled, Backspace will do nothing if you try to
delete a EOL marker.
This means you can only delete text that you've inserted since insert mode
started, and you can't delete any text that was previously inserted.
So what's the default setting?
I noticed this using GVIM in windows. The backspace seems to work as expected while using VIM from the terminal in most Linux systems however.
The reason for this is because many Linux distro's ship with pre-made vimrc files which set some common options. For example on my Arch Linux system I have
" ... and a few more...
If you install Vim on Windows, the default is to use the default vimrc and gvimrc that Vim ships with.
The Vim default is an empty value for
backspace. The Arch Linux, Debian, CentOS, or
$other_distro default may be different.
This question is about Backspace in insert mode, but let me also add some brief remarks about Backspace in normal mode.
In normal mode, the Backspace acts as
h, it just goes to the left.
By default, the backspace will go to the previous line if at the start of a line (as if
eol was in
backspace); you can control this behaviour with the
'whichwrap' option through the
b flag (enabled by default).
You can also make backspace delete characters by mapping it to the
nnoremap <BS> X