Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: what's the default backspace behavior?

Tags:

vim

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.

like image 438
ivan Avatar asked Sep 13 '13 03:09

ivan


2 Answers

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)

like image 118
Andon M. Coleman Avatar answered Oct 26 '22 04:10

Andon M. Coleman


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.

like image 43
FDinoff Avatar answered Oct 26 '22 04:10

FDinoff