Replace tabs with spaces in vim

前端 未结 11 1009
青春惊慌失措
青春惊慌失措 2020-12-02 03:38

I would like to convert tab to spaces in gVim. I added the following line to my _vimrc:

set tabstop=2

It works to stop at two

相关标签:
11条回答
  • 2020-12-02 03:59

    Try

    set expandtab
    

    for soft tabs.

    To fix pre-existing tabs:

    :%s/\t/  /g
    

    I used two spaces since you already set your tabstop to 2 spaces.

    0 讨论(0)
  • 2020-12-02 04:00

    first search for tabs in your file : /^I :set expandtab :retab

    will work.

    0 讨论(0)
  • 2020-12-02 04:04

    This got it working for me:

    :set tabstop=2 shiftwidth=2 expandtab | retab
    
    0 讨论(0)
  • 2020-12-02 04:08

    IIRC, something like:

    set tabstop=2 shiftwidth=2 expandtab
    

    should do the trick. If you already have tabs, then follow it up with a nice global RE to replace them with double spaces.

    0 讨论(0)
  • 2020-12-02 04:09

    Once you've got expandtab on as per the other answers, the extremely convenient way to convert existing files according to your new settings is:

    :retab
    

    It will work on the current buffer.

    0 讨论(0)
提交回复
热议问题