Vim: what's the default backspace behavior?

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.


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.

  • 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 ...")

  • vim's handling of control characters (eg 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)


    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.

    链接地址: http://www.djcxy.com/p/49452.html

    上一篇: 我如何配置2种不同语言的Vim?

    下一篇: Vim:默认的退格行为是什么?