Not all projects I am regularly working on use the same CodingStyle. This is very unfortunate, and sometimes makes it time consuming to provide acceptable patches. One common example is that some project indent with a
<tab>, where others expect
<4-spaces>.
I could not find a vim plugin or other extension that lets me pick vim-settings per git repository. The idea that I came up with, is to set the project specific vim-settings in the git-config itself. For example:
$ git config --add vim.settings 'tabstop=4 expandtab'
Now, in my ~/.vimrc, I have the following snippet:
let git_settings = system("git config --get vim.settings")
if strlen(git_settings)
exe "set" git_settings
endif
Editing a file in the git repository that contains the above vim.settings, now replaces my <tab> by <4-spaces>. Other repositories that do not have the vim.settings will fall-back to my vim defaults. If you can think of any improvements or suggestions, please share them.
3 comments:
This just gave gave me an idea for a solution I've been looking to solve..load a project specific vimrc that I keep in my project root dir.
I've never written vim script before so bare with me here.
" Source vimrc from git project root
let project_root = system("git rev-parse --show-toplevel")
" System commands seem to have a trailing newline, so lets get rid of that
let chomped_project_root = project_root[:-2]
let project_vimrc = chomped_project_root."/.vimrc"
if filereadable(project_vimrc)
execute "source" project_vimrc
endif
A similar, but less git specific solution, is this http://www.gslsrc.net/l004_vimrc_project_search_path.html
fyi, I created a gist for my version
https://gist.github.com/4617337
Thanks for sharing, Leif!
Post a Comment