vim:config:indentation:file_type_based_indentation:different_settings_for_different_file_types
Table of Contents
VIM - Config - Indentation - File type based indentation - Different settings for different file types
To have different indentation for different file types.
- html files to use tabs with 2-columns per indent,
- Python files use spaces with 4-columns per indent.
Enable file type detection
To apply suitable settings automatically, enable file type detection:
- ~/.vimrc
filetype plugin indent on
Create a setup file for HTML
Create a setup file for Python
Create file python.vim:
- python.vim
setlocal expandtab setlocal shiftwidth=4 setlocal softtabstop=4
The html.vim and python.vim files should be in this directory (which you may need to create):
~/.vim/after/ftplugin on Unix-based systems; or $HOME/vimfiles/after/ftplugin on Windows systems
The standard plugins probably do not change settings such as shiftwidth, and in that case the directory ~/.vim/ftplugin (or $HOME/vimfiles/ftplugin) would work as an alternative.
- However the after directory should be used because you intend to override settings from other plugins.
Using the after directory as above is recommended, but it is possible to put commands such as the following in your vimrc as an alternative:
autocmd FileType html setlocal shiftwidth=2 tabstop=2 autocmd FileType python setlocal expandtab shiftwidth=4 softtabstop=4
vim/config/indentation/file_type_based_indentation/different_settings_for_different_file_types.txt · Last modified: 2022/10/08 15:42 by peter