9

I'm setting up my vimrc file. I understand adding set backspace=indent,eol,start allows the backspace to behave "normally" (deleting indentation, line breaks, pre-existing characters) while in insert mode, but I'm confused whether I need to add this line to my file or whether it's the default behavior.

I've tried running Vim without that line, even without a vimrc file, and the backspace still worked normally. I should mention that I'm on a MacBook, and the key is actually labeled "delete", but I'm assuming that's irrelevant.

2 Answers 2

13

Generally it does not matter that it is called "Delete" on Mac keyboards. Technically Apple gets away with this by calling that key "Backward Delete". And what we traditionally think of as a delete key, Apple calls "Forward Delete". To get "Forward Delete" behavior you must press fn + delete.

Now, back to the real issue, vim... the default setting for backspace in OS X is this (/usr/share/vim/vimrc):

set backspace=2 " more powerful backspacing

Your custom vimrc should override this if you want the behavior you discussed in your question.


There are two other factors that may lead to strange behavior with respect to backspace in vim.

  1. Terminal software can be configured to send either Delete or Backspace when you press this key. (This option is usually called something like "send ^H on ...")

  2. vim's handling of control characters (e.g. backspace / delete) differs depending on your terminal string, I have found xterm-color generally works best in OS X's terminal emulator.


My Terminal settings in OS X:

Declare terminal as: xterm-color

[ ] Delete sends Ctrl-H (unchecked)

3
  • Hmm, so I guess my confusion is actually stemming from which vimrc file is being found/used. I might need to post a new question. Thanks for the help!
    – ivan
    Sep 13, 2013 at 3:53
  • @ivan: Well, there is the system-wide vimrc file that is loaded first, and then vim will load the user vimrc (usually ~/.vimrc). You can override any setting from the system-wide config file in your own, but if you fail to do so it will take on the system-wide default. That is why it is difficult to say conclusively what the "default" is - it really depends on how your system is configured. I suggest you run: vim --version to find out for sure what your system vimrc is configured as, in OS X it should be /usr/share/vim/vimrc. Sep 13, 2013 at 3:57
  • Ah, now I see. I was already using the version command to try and pin down the situation, but got a bit confused along the way. Bouncing between two different versions of vim (7.3 preinstalled, 7.4 MacVim) wasn't helping any, nor was the late hour and all those environment variables :)
    – ivan
    Sep 13, 2013 at 4:07
9

The vi compatible backspace can be set with

set backspace=

This turns off the following.

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 hitting backspace will only delete what has been inserted in the current insert mode and on the current line. This makes deleting in insert mode very difficult.

Using the default backspace option also leaves the old characters on the screen and they won't disappear until you exit back to normal mode.

As @Andon says though it is being overwritten by your system vimrc. So you should put the line in your vimrc just incase you move it to another system which doesn't have the same system vimrc.

You can test vim with no vimrc by running vim -u NONE and will run with the default backspace settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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