Developing software in the Real World

Using .vimrc for project specific settings

I’m more of a spaces person than a tabs person when it comes to source code and in Vim, I like to see the tab characters, so I have this setting:

This places a handy character so that I can see the tabs:

Shoppping list with tabs

I’m currently working on a codebase where the coding style is to use tabs, so I need to change my settings. One option is to use EditorConfig, for the formatting changes, but it doesn’t help with the Vim specific display setting.

To solve this, I’m using a .vimrc file the root of my project with this setting:

By default, Vim doesn’t read .vimrc files in the current directory, so we need to enable this feature in our main .vim/vimrc file:

The exrc setting adds searching of the current directory for the .vimrc file and loads it.

Enabling the secure setting ensures that shell, autocmd and write commands are not allowed in the .vimrc file that was found in the current directory as there’s no need to take risks.

Now, I can have tabs displayed in all my other projects, but in this specific one, they aren’t!

Shoppping list with no tabs

One thought on “Using .vimrc for project specific settings

  1. A caveat worth noting from :help secure (http://vimdoc.sourceforge.net/htmldoc/options.html#'secure'):
    On Unix this option is only used if the ".vimrc" or ".exrc" is not owned by you. This can be dangerous if the systems allows users to do a "chown".

    This also means that if you git clone a repository from someone you don't trust and open a file in it, they could have included a malicious .vimrc that will be sourced, since it's owned by you even though someone else wrote it.

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *