Wrong indentation when editing Yaml in Vim

前端 未结 7 1106
一整个雨季
一整个雨季 2021-01-30 03:50

Vim does not seem to correctly react at a dash symbol in YAML files therefore breaking the format.

For example I have a block which should look like this:



        
7条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 04:25

    You can use this autocommand to make Vim properly indent YAML files (put it to your .vimrc):

    " Fix auto-indentation for YAML files
    augroup yaml_fix
        autocmd!
        autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab indentkeys-=0# indentkeys-=<:>
    augroup END
    

    Basically, for YAML file it instructs Vim to:

    • Use 2 spaces for indentation.
    • Use spaces instead of tabs.
    • Skip re-indenting lines after inserting a comment character (#) at the beginning of a line, or a colon.

提交回复
热议问题