Delete key doesn’t work in vim on iTerm2

itermkeyboardterminal

Firstly, I typed some thing on insert mode, like

Hello

At this stage, if I didn't exit from insert mode, delete works and can delete the whole word if I want.

If I quit insert mode, and open insert mode again, this Hello can't be removed by delete. But the newly typed in content can be removed.

I've renamed my .vimrc, problem still exits.

And I did some test on remote server through iterm, didn't encounter the same issue.

What could be the cause of this problem? How to fix it?

Best Answer

This is a feature of vim, although IIRC it wouldn't be enabled by default.

backspace is a setting in vim, and you can set three different parameters: indent, eol, and start

If you run :help backspace, it will tell you:

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.

The one that isn't set for you is start.

If you add set backspace=indent,eol,start to your .vimrc, you'll be able to backspace over anything in insert mode.