Local .vimrc

Well, I’m sure it’s something well known, but I just discovered it, so here I am.

Ok, let’s assume you work on projects that would require you to have this in your .vimrc:

set autoindent
set cindent
set shiftwidth=4
set expandtab

But also on other projects that would require this:

set autoindent
set cindent
set shiftwidth=8
set noexpandtab

How to deal with that? Local configuration ViM script to the rescue. Basically, it is enough to:

  1. copy the content of (or source) this file in your actual ~/.vimrc;
  2. create a file called .lvimrc in the root directories of your projects.

Of course, you can have one different .lvimrc for each project, and thus put the first group of lines above in the .lvimrc residing in the source tree of the projects that like spaces, and the second group of lines in the .lvimrc residing in the source tree of the projects that like tabs.

Tested right now on ViM version 7.3.712 that comes with Fedora 18, and it works.

Oh, of course, I’m also assuming that you use ViM, and that you do that for writing code (in C!), and you use auto-indentation... I might better have said this before, but come on, who doesn’t do that these days! 😛


About dariofaggioli

Interested in CS, programming and Open Source since like forever, I'm now a very happy Virtualization developer @ SUSE. Much more important, I am a dreamer, a madly in love husband and an enthusiastic & incredibly proud father.
This entry was posted in Fedora, Linux, Technology and tagged , , , , , , , , . Bookmark the permalink.

8 Responses to Local .vimrc

  1. Andreas Schneider says:

    I don’t think it is a good idea to simply execute that file. This would be a security risk. Someone could trick you to checkout a git repo and when you open a file execute arbitrary code.

    You need to limit it to certain commands which are allowed. Which is probably


    maybe some more but not the whole stack of commands. The idea is good but dangerous 🙂

    • Mmm… I see what you mean and yes, I think that is a fair point… not for security maniacs! 🙂

      Actually, restricting the scope of what command can be executed is a nice idea, but I don’t have the slightest idea on how to do that, do you?

      Anyway, thanks for the interest.

  2. Andreas Schneider says:

    Do you know modelines in vim?
    :help modeline

    They are limited only to the set command cause of security reason. I would suggest that you only allow set command to be in the local vim rc or in the git config (I would prefer the git config way). So you read the file or git config and append it to


  3. gladiac says:

    git config –add vim.modeline “tabstop=8 shiftwidth=8 noexpandtab”

    Edit ~/.vimrc and add:

    " Support for vim modeline in git config.
    let git_config_modeline = system("git config --get vim.modeline")
    if strlen(git_config_modeline)
        exe "set" git_config_modeline

Leave a Reply to Andreas Schneider Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.