Tabs and spaces in vim

前端 未结 6 1123
生来不讨喜
生来不讨喜 2021-01-29 18:07

How do I prevent vim from replacing spaces with tabs when autoindent is on?

An example: if I have two tabs and 7 spaces in the beginning of the line, and tabstop=3

6条回答
  •  隐瞒了意图╮
    2021-01-29 18:42

    all I want is the autoindented line to have exactly the same indentation characters as the previous line.

    :help copyindent

    'copyindent' 'ci' boolean (default off); local to buffer; {not in Vi}

    Copy the structure of the existing lines indent when autoindenting a new line. Normally the new indent is reconstructed by a series of tabs followed by spaces as required (unless 'expandtab' is enabled, in which case only spaces are used). Enabling this option makes the new line copy whatever characters were used for indenting on the existing line. If the new indent is greater than on the existing line, the remaining space is filled in the normal manner.

    NOTE: 'copyindent' is reset when 'compatible' is set.
    Also see 'preserveindent'.

    :help preserveindent

    'preserveindent' 'pi' boolean (default off); local to buffer; {not in Vi}

    When changing the indent of the current line, preserve as much of the indent structure as possible. Normally the indent is replaced by a series of tabs followed by spaces as required (unless 'expandtab' is enabled, in which case only spaces are used). Enabling this option means the indent will preserve as many existing characters as possible for indenting, and only add additional tabs or spaces as required.

    NOTE: When using ">>" multiple times the resulting indent is a mix of tabs and spaces. You might not like this.
    NOTE: 'preserveindent' is reset when 'compatible' is set.
    Also see 'copyindent'.
    Use :retab to clean up white space.

提交回复
热议问题