Vim: what is the default backspace behavior?

I am creating my vimrc file. I understand that adding set backspace=indent,eol,start allows backspace to behave "normally" (removing indentation, line breaks, existing characters) in insert mode, but I'm confused if I need to add this line to my file or by by default.

I tried running Vim without this line, even without a vimrc file, and backspace still worked fine. I have to mention that I am on a MacBook and it actually means “delete” on it, but I assume it doesn’t matter.

+6
source share
2 answers

Generally, it doesn't matter what it's called "Delete" on Mac keyboards. Technically, Apple gets away with this by calling this key “Backward Delete”. And what we traditionally see as the removal key, Apple calls Forward Delete. To get the "Forward Delete" behavior, you must press fn + delete .

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

set backspace = 2 "more powerful backspace

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


There are two other factors that can lead to weird backspace behavior in vim.

  • The terminal software can be configured to send either "Delete" or "Backspace" by pressing this key. (This option is usually called something like "send ^ H on ...")

  • The handling of vim control characters (e.g. backspace / delete) varies depending on your final string, I found that xterm-color usually works best in an OS X terminal emulator.


My terminal settings in OS X:

Declare terminal as: xterm-color

[] Delete sends Ctrl-H (unchecked)

+6
source

Vi-compliant compatibility can be established using

 set backspace= 

This disables 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. 

Thus, clicking on the backspace will delete only what was inserted into the current insert mode and into the current row. This makes it very difficult to delete in insert mode.

Using the default backspace option also leaves the old characters on the screen and they will not disappear until you return to normal mode.

As @Andon says it is being overwritten by your vimrc system. Therefore, you should put the string in your vimrc simply if you move it to another system that does not have the same vimrc system.

You can test vim without vimrc by running vim -u NONE and making default settings for backspace.

+7
source

Source: https://habr.com/ru/post/953745/


All Articles