Project specific settings in Vim

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:

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
            setlocal tabstop=4 shiftwidth=4
    elseif l:path =~ '/home/user/projects'
        setlocal tabstop=4 shiftwidth=4 noexpandtab
autocmd! BufReadPost,BufNewFile * call SetupEnvironment()