Can Vim display two spaces for indentation, while keeping four spaces in the file?

前端 未结 3 499
一生所求
一生所求 2021-02-07 13:54

I want to work on someone else\'s project, and he uses 4 spaces for indentation. I use 2, and my screen is not big enough to edit using 4 spaces comfortably.

Can I confi

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-07 14:05

    The help has an example for a similar use case of different tab widths, see :help retab-example.

    Adapting that to halving / doubling spaces:

    :autocmd BufReadPost,BufWritePost  * %substitute/^\( \+\)\1/\1/e
    :autocmd BufWritePre               * %substitute/^ \+/&&/e
    

提交回复
热议问题