vim autoindent + :set bs=0 + ctrl+u is broken

Bug #44431 reported by Allison Karlitskaya
4
Affects Status Importance Assigned to Milestone
vim (Ubuntu)
Fix Released
Medium
Scott James Remnant (Canonical)

Bug Description

Vim takes a backspace= option to determine how far it should diverge from the class Vi backspace behaviour (which states that backspace will not erase things not entered in the current insertion).

It has 3 options:
  indent - backspace will erase indenting created by autoindent
  eol - backspace will erase across newlines
  start - backspace will erase past the start of insertion

You can use 0 to disable all of the options. The setting is also supposed to affect CTRL+W and CTRL+U.

There is a corner case there this doesn't work.

vim somefile.c

:set bs=0

int
main (void)
{
     (vim indents this line)

on the indented line if you press backspace or ^W or ^U nothing happens because the backspace option says that you are not able to erase autoindented spaces. Good.

Type some text in here. Erase it using backspace or ^W. Notice that the erasing stops at the start of your typing. In all cases so far Vim has prevented you from erasing the indent characters.

Now: enter some text and type ^U to erase it. The indent character are now gone. The one case where it would be most useful to prevent you from erasing the autoindent characters (ie: ^u to restart typing the current line) is the exact case where you get shot in the foot.

Revision history for this message
Allison Karlitskaya (desrt) wrote :

The problem is in edit.c in the function ins_bs() at this line:

        if (mode == BACKSPACE_LINE && curbuf->b_p_ai

as it turns out, the default Ubuntu vim config has 'autoindent' _disabled_ (ie: curbuf->p_p_ai is 0). For some reason, the autoindenting still happens though.

So basically, with the Ubuntu config:
  - autoindent is actually enabled (in that it occurs)
  - but the autoindent option proper is not actually set (so the backspace code breaks)

Revision history for this message
Allison Karlitskaya (desrt) wrote :

Offending config file entry:

    filetype plugin on

Looks like the 'filetype' plugin is to blame.

Revision history for this message
Allison Karlitskaya (desrt) wrote :

The real offender:

     :set cindent

enables indenting but doesn't set the "autoindent enabled for this buffer" flag. Probably a result of C being "special" in vim.

Revision history for this message
Allison Karlitskaya (desrt) wrote : patch to fix

this patch fixes the bug by modifying the conditional to check if cindent is enabled as well as the normal autoindent.

it fixes the problem for me.

Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote :

Patch applied

Changed in vim:
assignee: nobody → keybuk
status: Unconfirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.