Home  >  Q&A  >  body text

How to provide different indent widths for different code files in vim?

How to set different tab space widths for different code files (which can be simply judged by the suffix name) in the .vimrc file? For example, the tabs of .rb files are indented by two spaces at a time, the tabs of .c files are indented by three spaces, and the tabs of .cs files are indented by four spaces, similar to this. PS: It only needs to be used on linux and osx. Thanks in advance to all those who provided answers.

曾经蜡笔没有小新曾经蜡笔没有小新2736 days ago1088

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-05-16 16:43:26

    Just set it according to the file type, as follows.

    "为不同的文件类型设置不同的空格数替换TAB
    autocmd FileType php,python,c,java,perl,shell,bash,vim,ruby,cpp set ai
    autocmd FileType php,python,c,java,perl,shell,bash,vim,ruby,cpp set sw=4
    autocmd FileType php,python,c,java,perl,shell,bash,vim,ruby,cpp set ts=4
    autocmd FileType php,python,c,java,perl,shell,bash,vim,ruby,cpp set sts=4
    autocmd FileType javascript,html,css,xml set ai
    autocmd FileType javascript,html,css,xml set sw=2
    autocmd FileType javascript,html,css,xml set ts=2
    autocmd FileType javascript,html,css,xml set sts=2
    

    reply
    0
  • Cancelreply