30

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?

5
  • With 'delete' you mean backspace? Removing whole words in insert mode can be done with Ctrl-W, try that. If that does nothing, there's something wrong with your vim. I use iTerm 2 and have never had such problems.
    – oarfish
    Commented Feb 17, 2015 at 14:18
  • Yes, I can use dw or dw+shift in normal mode to delete words. But backspace and ctrl + w both don't work in the second situation I mentioned above.
    – ZengJuchen
    Commented Feb 17, 2015 at 15:07
  • But you can use backspace on the normal command line outside vim? Very weird.
    – oarfish
    Commented Feb 17, 2015 at 21:00
  • @oarfish, yes, I can, and in remote server vim I don't have such problem, all just happens in a sudden. I can't get the clue for now.
    – ZengJuchen
    Commented Feb 19, 2015 at 2:28
  • What vim version do you have? I have vim 7.4.481, and I can't reproduce the problem.
    – jan.h
    Commented Feb 24, 2015 at 0:29

3 Answers 3

24
+50

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.

1
  • "feature"... For some reason, I'm seeing it enabled by default on a fresh macOS 10.13 with a brew install of vim latest. This solution still resolves the issue. Commented Oct 8, 2018 at 17:59
33

I also had this, the natural text processing default values were wrong for me.

  • MacBook Pro (15-inch, 2018)
  • 10.14.3 (Mojave)
  • Iterm2 3.2.7

Go to Preferences > Profiles > Keys and load the default preset Natural Text Editing and delete all entries that are about delete and delete behaviour. After that it works as expected.

9
  • 9
    Same, except I just removed the entries about "Del->", but did not add a "Sends ^H" binding. Then it worked as expected.
    – DagW
    Commented Mar 25, 2019 at 8:38
  • 3
    Had to dig too deep into wrong posts just to find this as the right answer, thanks a lot! Commented Oct 21, 2019 at 7:26
  • 2
    Yes! this is about iterm configuration, not vim itself. Commented Dec 31, 2019 at 7:05
  • 2
    Will there be any other side effects of removing these delete entries?
    – Magnus
    Commented Feb 16, 2020 at 2:22
  • 2
    FYI I also have Natural Text Editing enabled, and only had to remove the mapping for Del->0x4
    – jjj
    Commented Jul 16, 2021 at 18:32
3

In my case, after trying all the possible solution found on internet, it was just that the option Delete key sends ^H was not selected.

So make sure that this option is selected here : iTerm2 > Preferences > Profiles > Keys

2
  • its below the "presets" drop down on the bottom, but does not help for vim on MBP 2021 Monterey Commented Jan 31, 2022 at 7:12
  • "was not selected": do you mean you had to add it or remove it to make it work? Commented Aug 19, 2022 at 1:20

You must log in to answer this question.

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