How to provide different indent widths for different code files in vim?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 16:41:26
0
1
1107

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.

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(1)
左手右手慢动作

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template