Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Backspace in Insert mode sometimes moves the cursor back one before deleting #79

Open
roryokane opened this issue Feb 24, 2018 · 0 comments

Comments

@roryokane
Copy link

roryokane commented Feb 24, 2018

Bug description

When a document is set up like this, with a two-letter word started and the cursor in the first line of a wrapped line (with :set wrap):

▌foo foo foo foo re▐
▌|                 ▐
Legend
  • = left margin of window
  • = right margin of window
  • | = cursor in Insert mode

Sometimes, pressing Backspace will delete the second-to-last character r and place the cursor where it had been:

▌foo foo foo foo |e▐

instead of deleting the last character e and being in this desired state:

▌foo foo foo foo r|▐

I kept running into this bug while typing up two-sentence log entries and sometimes using Backspace to delete words I wanted to retype.

A test case to reproduce the bug with

One of my files to reproduce the bug in contained this:

Test cases, for an 80-character-wide window:

Go to the end of this line, append “ 12”, and press Backspace. The bug is reproduced.

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww 12

Go to the end of this line, delete a character, append “w 12”, and press Backspace. The bug is reproduced.

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

I couldn’t always reproduce the bug with this, though. If I did other edits to the file, undid them, and then followed the reproduction steps, sometimes the bug wouldn’t trigger.

Cause of the bug

The cause of the bug is the inoremap <BS> mapping defined within plugin/AutoClose.vim. When I run :imap <BS>, I can see that that is the only mapping that would trigger.

Workaround

My workaround was uninstalling AutoClose and switching to delimitMate.

roryokane added a commit to roryokane/dotvim that referenced this issue Feb 24, 2018
`AutoClose--Alves` had two bugs that delimitMate avoids:

• With AutoClose, typing a single quote always inserted two single quotes, even in words like “don't” where I mean the quote as an apostrophe. DelimitMate’s “smart quotes” feature fixes this (the feature has nothing to do with typographic quotes).
• AutoClose’s insert mode mapping for <BS> (backspace) had a bug that could delete the wrong character sometimes. Pressing backspace when the cursor was on the first column of a wrapped line would sometimes move the cursor back one character before doing the delete, having the effect of deleting the second-to-last character in the previous line. I wrote more details about the bug in Townk/vim-autoclose#79.

AutoClose hadn’t been updated for five years, so I had to switch to a different plugin. I had three choices for replacements:

• https://vimawesome.com/plugin/delimitmatehttps://vimawesome.com/plugin/auto-pairshttps://vimawesome.com/plugin/lexima-vim

I ruled lexima.vim out because it doesn’t have the smart single quotes feature, and isn’t very popular. So the final choice was between delimitMate and Auto Pairs.

DelimitMate and Auto Pairs are close in popularity and in thoroughness of documentation, but delimitMate has unit tests and Auto Pairs doesn’t. Also, Auto Pairs has a disabled-by-default Fly Mode that clutters up its feature set. I would never use that mode, and delimitMate has plenty of customization but no unusual modes. So finally I chose delimitMate.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant