41

File foo has text:

This| is a line.

If I place the cursor at the |, hop into insert mode, and press backspace, nothing happens. If I type something, I can delete the things I've typed, but only back to where the insertion began. For example, if I place the cursor at the end of the line, and type word, I can delete word but can't delete the . or anything to the left of it.

This is rather annoying. What vim setting does this?

3
  • 1
    Some say you fix that by using the vim setting in emacs.
    – zortacon
    Commented May 23, 2012 at 20:36
  • 1
    You can always place cursor over the character and push d then l. That will delete 1 character going right. Commented May 23, 2012 at 20:37
  • 1
    @scrappedcola, you could also save a keystroke by simply typing x. But if you want to change the character, you can use r<newchar>, or, to enter insert mode, cl, which can come in pretty handy. (in fact, c<any motion> works) Commented Jun 13, 2015 at 4:14

2 Answers 2

83

Explanation

The 'backspace' setting controls this behavior.

From the help page:

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.

Changing backspace behavior

Try adding the following to your .vimrc:

set backspace=indent,eol,start " backspace over everything in insert mode

A short-hand version of the same command:

set backspace=2
0
-1

If you're using vim:

vim ~/.vimrc

If you're using vi:

vi ~/.exrc

Then add this line to the top of the file:

set nocompatible

Save the file and that should fix it

1
  • The existence of a vimrc is enough to trigger nocompatible, see :help 'compatible'. Furthermore, your answer implicitly relies on Vim's default cpoptions. Specifically the absence of the v flag, see :help cpo-v. Unless you have a very good reason for doing so, don't use ~/.exrc. This is generally bad advice.
    – Friedrich
    Commented Nov 24, 2023 at 10:11

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