If you work in different environments, each with its own different coding standards and rules, then your projects are going to be in separate directories that usually don't interact with each other. You can use that to let Vim know, from the path in which the projects reside, what rules to apply for each individual project.
For example, you might have a few projects with the following details:
/home/user/projects/Project1, and the rules state that tabs should be replaced with 4 spaces in all files that are not YAML, and with 2 spaces in YAML files
/home/user/projectsand have the rules that tabs remain tabs in all files, and they should be treated as being equal with 4 spaces
To accommodate the above scenario, you could define an
autocmd in your
.vimrc file for switching between rules, depending on the file path:
function! SetupEnvironment() let l:path = expand('%:p') if l:path =~ '/home/user/projects/Project1' setlocal expandtab smarttab textwidth=0 if &filetype == 'yaml' setlocal tabstop=2 shiftwidth=2 else setlocal tabstop=4 shiftwidth=4 endif elseif l:path =~ '/home/user/projects' setlocal tabstop=4 shiftwidth=4 noexpandtab endif endfunction autocmd! BufReadPost,BufNewFile * call SetupEnvironment()