30

I opened vim in my iterm2. Firstly, I typed something on insert mode, like

Hello

At this stage, if I didn't exit from insert mode, delete key 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 key. But the newly typed-in content can be removed.

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

In the shell command-line, my delete key works well.

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?


PS: As I'm using macbook, the delete key is corresponding for backspace in PC.

0

4 Answers 4

50

Just put this to your .vimrc :

set backspace=indent,eol,start
6
  • 1
    Thanks a lot saving my time :) Dec 3, 2019 at 8:34
  • 4
    @Gawain, can you please explain the solution? Thanks. Mar 10, 2021 at 8:31
  • What is a ".vimrc"? Is there a filepath for this?
    – John Smith
    Jun 14, 2022 at 8:17
  • @JohnSmith ".vimrc" file is in your home directory.
    – Agnibha
    Jul 18, 2022 at 9:45
  • @JohnSmith edit: vim ~/.vimrc Oct 23, 2023 at 23:31
12

Check for the iTerm key mappings (Preferences -> Profiles -> Keys). I was using the default Natural Text Editing preset, and by this answer, deleting the key mappings related to delete solve the issue for me.

2
  • This was the problem on my case 👌
    – Victor
    Sep 7, 2022 at 14:32
  • Thanks for the answer! In my case, I only needed to remove a single key mapping, namely the one for "Del→". Sep 14, 2022 at 11:11
4

This is nothing to do with the shell, or with the version of vim. It's a simple configuration thing, as the operation of backspace in insert mode is ordinary vim configurable behaviour. Specifically, it is vim's backspace setting. On one machine you (most probably) have that set to the empty string, and on another you have it set to include the value start. And this is probably in a global configuration file.

Note that the default if you bring up vim in vi-compatible mode is for the backspace variable to be the empty string. The behaviour that you are complaining about is in fact the behaviour of the original vi. Linux operating systems tend to fill the global configuration file with all sorts of vim options that turn on "friendlier" behaviours that deviate from that of original vi. The BSDs tend not to.

Further reading

  • Arnold Robbins, Elbert Hannah, and Linda Lamb (2008). "Simple Editing". Learning the vi and Vim Editors. O'Reilly Media, Inc.. ISBN 9781449313258. p. 14.
  • :help backspace. vim documentation.
  • Bug #19903. 1998. Debian BTS.
1

I believe this might due to the version of vim installed on OSX by default. You can always install vim via homebrew and see if that replacement helps. I found this page that kind of helps supe up the OSX terminal experience. https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/

Take note of this line 'brew install vim --override-system-vi'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .