Tabs and spaces in autoindent mode

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Tabs and spaces in autoindent mode

Anton Shepelev
Hello, all

In autoindent and noexpandtab mode, Vim will sometimes
repace a carefully chosen combination of tabs and spaces
with another, in which all the spaces are replaced with tabs
except a few trailing ones, corresponding to the remainder
of dividing the indent width by tab width.

The following example uses a tab width of 3 characters. Both
the lines have a single level of indentation, but the second
line is additionally aligned with the `source' inentifier
above, using spaces. It looks thus:

   SomeTypeOfMine source,
                  destination;

If I denote tabs with `_' and spaces with `.' to show the
indentation structure:

___SomeTypeOfMine source,
___...............destination;

When, however, I add a third line, Vim replaces the
alignment spaces with tabs:

___SomeTypeOfMine source,
___...............destination,
__________________buffer;

whereas I expect it not to interfere with my alignment and
retain the tab-space combination:

___SomeTypeOfMine source,
___...............destination,
___...............buffer;

Is it possible?

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200914200825.706f5dc47d7c8d9b3d9c1c8d%40gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Tabs and spaces in autoindent mode

Gary Johnson-4
On 2020-09-14, Anton Shepelev wrote:

> Hello, all
>
> In autoindent and noexpandtab mode, Vim will sometimes
> repace a carefully chosen combination of tabs and spaces
> with another, in which all the spaces are replaced with tabs
> except a few trailing ones, corresponding to the remainder
> of dividing the indent width by tab width.
>
> The following example uses a tab width of 3 characters. Both
> the lines have a single level of indentation, but the second
> line is additionally aligned with the `source' inentifier
> above, using spaces. It looks thus:
>
>    SomeTypeOfMine source,
>                   destination;
>
> If I denote tabs with `_' and spaces with `.' to show the
> indentation structure:
>
> ___SomeTypeOfMine source,
> ___...............destination;
>
> When, however, I add a third line, Vim replaces the
> alignment spaces with tabs:
>
> ___SomeTypeOfMine source,
> ___...............destination,
> __________________buffer;
>
> whereas I expect it not to interfere with my alignment and
> retain the tab-space combination:
>
> ___SomeTypeOfMine source,
> ___...............destination,
> ___...............buffer;
>
> Is it possible?

Try setting 'copyindent'.  That should do what you want.  See

    :help 'copyindent'

HTH,
Gary

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200914172147.GA20505%40phoenix.
Reply | Threaded
Open this post in threaded view
|

Re: Tabs and spaces in autoindent mode (and Does anyone today need auto/smartindent without copy and preserveindent?)

Gabriele Fava
In reply to this post by Anton Shepelev
On 14/09/2020 19.08, Anton Shepelev wrote:
> Hello, all
>
> In autoindent and noexpandtab mode, Vim will sometimes
> repace a carefully chosen combination of tabs and spaces
> with another <snip>

This is solved (hopefully) by enabling the 'copyindent' and
'preserveindent' options.

The problem resurfaces periodically in the mailing lists.

I have run into it recently and have been meaning to say something about it.

There is terrible documentation (in :h 'autoindent' and :h 'smartindent'
'copyindent' and 'preserveindent' are not mentioned and there are lies
about what they do by default - "Copy indent from current line"? Not
really! -), a puzzling arrangement of options (but that's for historical
reasons) and arguably senseless defaults.

The real behaviour of 'autoindent' and 'smartindent' is better described
(only) in the documentation of 'copyindent' and 'preserveindent' (but
even there it's not complete, there should probably also be a mention of
how Vim converts spaces to tabs - namely looking at the 'shiftwidth'
option, if I'm not mistaken).

Looking in the repository it seems that the missing correction of the
'autoindent' and 'smartindent' documentation was an oversight of the
original patch that introduced copyindent and preserveindent (vim-6-2d),
and was never corrected.

Does really anyone today require 'auto/smartindent' without 'copyindent'
and 'preserveindent'??? And for that to be the default??

I read somewhere in vim-dev that some tools did seem to rely on the
default autoindent behaviour, but even if it were still so breaking
changes are not unheard of in Vim.

In any case, I think that there should at the minimum be very prominent
notices that unless you have very peculiar needs you should enable
copyindent and preserveindent before enabling auto or smartindent.

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/f3e3daf2-e4b8-4a0a-4db1-d9d1b2b71151%40tiscali.it.