Tab Vs Space preferences in Vim

前端 未结 7 1074
眼角桃花
眼角桃花 2020-12-07 07:31

Vim is very accommodating when it comes to tab Vs. space preferences. As I understand it, the tabstop setting indicates the width of a tab character. The

7条回答
  •  孤城傲影
    2020-12-07 07:59

    Your understanding of softtabstop and expandtab is wrong - so the stab option you suggest wouldn't be very useful.

    expandtab is for when you want to use spaces instead of tabs for everything. If you set expandtab, then Vim ignores the softtabstop option and uses tabstop and shiftwidth to work out how many spaces to insert.

    softtabstop is only for when you would like to use a mix of tabs and spaces, allowing you to indent with fine control (2 or 4 spaces), while keeping tab width at a higher value (usually 8) so that text appears in the other applications. Setting softtabstop=tabstop doesn't accomplish anything because Vim will always use tabs for indenting.

    Update: As kaizer.se has pointed out, if you are using expandtab, then you still need to set softtabstop if you want Vim to backspace multiple spaces as though they are a tab.

提交回复
热议问题