I've stumbled over the unfortunate tendency of 'preserveindent' to mix spaces and tabs [1] -- as noted in the help [2], but nonetheless unexpected -- enough times now that I've been looking into the history of this feature and why this behavior exists, and I've found a couple of interesting points:

- 'preserveindent' doesn't seem to be widely used or understood.  Trying
  to find any information on its expected behavior is an exercise in
  frustration, and almost every available piece of advice on using it
  seems to be attached to a suggestion to enable 'copyindent', without any
  explanation of the distinction between the two -- suggesting that all
  such advice is of the cargo cult variety.  An admittedly incomprehensive
  set of searches appears to reinforce this hunch [3].

- There was a patch adding a 'leftindent' option, posted back in 2005 [4],
  that works by only adding or removing indentation at the left end of a
  line.  This patch adds a somewhat complex dependency on 'softtabstop'
  and 'preserveindent', but otherwise seems workable.

It doesn't look like it'd be too much work to update that patch, add tests, etc., but before I get too far down that path: would it make more sense to just make 'preserveindent' work this way instead? I'm inclined to think that's the obvious expectation, and can't think of any cases where it wouldn't be, especially as "spaces before tabs is bad" is just about the only thing widely agreed upon when it comes to indentation...

I know this comes down to a bit of a backward compatibility argument, but with that said and with Vim 8 on the horizon, does anyone actually expect or want the current behavior?

-Rob


[1] Starting with text like this, with >- markers denoting tabs:

-------foo(a,
-------    b);

Shifting this text with 2>> (or visual >, etc.) produces this:

------->-------foo(a,
-------    >---    b);

And again for further levels:

------->------->-------foo(a,
-------    >---    >---    b);

Tested with ":set pi noci noet ts=8 sw=8 sts=0" in all cases, although similar behavior exists for other combinations.

[2] Specifically, this note under 'preserveindent' in options.txt:

        NOTE: When using ">>" multiple times the resulting indent is a mix of
        tabs and spaces.  You might not like this.

Curiously, this note has been present in the current repository since the initial commit of Vim 7, but was not in the original patch submission:

        http://marc.info/?l=vim-dev&m=104335046130907&w=2

[3] Compare Google searches for

        site:github.com vimrc "copyindent"
        site:github.com vimrc "preserveindent" "copyindent"
        site:github.com vimrc "preserveindent" -"copyindent"

As I write this, these yield 2,200, 417, and 79 results, respectively. As further evidence, every hit on the first page of results for that last query has the option buried in a near-identical block of other settings, and several of those include inaccurate comments that suggest it has something to do with autoindent or filetype indent.

[4] http://permalink.gmane.org/gmane.editors.vim.devel/10621

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui