vimprj : Plugin for managing options for different projects
| script karma
Downloaded by 6556
Comments, bugs, improvements
script versions (upload new version)
|Please note: there's dependency DfrankUtil (vimscript #3884)
* * *
I've published a thorough article on Vimprj + Indexer usage; consider reading it: http://dmitryfrank.com/articles/vim_project_code_navigation
* * *
Many times i faced a problem. That's the story:
I'd like to use 3-space indent in my projects.
No tabs, especially three spaces. One day i need to work on another project
written by someone else, and there's 4 spaces indent. Or maybe tabs.
I need to work on this project too, and i need to keep existing formatting
I strongly dislike that i have to switch these options by hand: &shiftwidth,
And then i decided to write this plugin to make my life easier.
Using this plugin is quite easy. You need to create in the root directory of
your project new directory ".vimprj" and put any number of files "*.vim" in it.
Every time you open new file in Vim, plugin looks for ".vimprj" directory up
by tree, and if it is found, then all *.vim files from it will be sourced.
OR: you can just put file ".vimprj", then this file will be sourced.
Name ".vimprj" can be changed by editing option g:vimprj_dirNameForSearch .
Usually for my own projects i create just one file .vimprj/my.vim with the
following contents: >
let &tabstop = 3
let &shiftwidth = 3
(my .vimprj directory also contain tags and other project-specific files,
so, i'd prefer to use directory instead of just one file.)
and for other projects i create file with appropriate options.
Now, when i open file from my project, file my.vim is sourced. When i open
file from some another project, its own file with options is sourced too. Of
course, when i switch buffer, this files are sourced too if project is
So, i always have correct options, and simultaneus work on several projects
with different formatting options is not painful anymore for me.
And, of course, you can use it not only to manage formatting options. For
instance, in some my projects i use mapping <F9> to open project window
(from plugin project.tar.gz), but for some java projects i use Eclim, and <F9>
should be mapped to another command (to open Eclim's project).
All these options can also be stated in .vimprj dir.
There is an issue: as i already said, i would like to use shiftwidth=3. Say,
i open some file from my project with shiftwidth=3. All ok here. Then i open
file from another project with shiftwidth=4. All is still ok. Then i open some
file not from any project (there's no ".vimprj" directory). Of course, i would
like to use my favorite options (e.g. shiftwidth=3), but now shiftwidth is 4,
because it was changed when i opened last project. It leads us to the fact
that we should define default options. But here let me make a digression.
Plugin provides some hooks for any other plugin. For instance, plugin
Indexer (since version 4.0) uses these hooks to provide correct behavior
when user works on different project simultaneusly.
Right now i have not documented yet all these hooks, because of lack of
free time, but i just tell you about one hook, to let you specify your
This is a hook "SetDefaultOptions". Now i show you an example. Please insert
in your .vimrc the following, just specify your own default options instead of
mine ones: >
" your default options goes here!
" initialize vimprj plugin
" define a hook
Now vimprj plugin will call your function SetMainDefaults just before sourcing
all *.vim files from .vimprj directory, and when you open file not from any
If you are interesting about another hooks, you can just look how is they used
in Indexer plugin (since version 4.0). I hope one day i will write all this here. =)
Please NOTE: by default this plugin will change your current dir
to project's dir if ".vimprj" is found.
More detailed read in help: type :help vimprj-options , look for an option
Development repository (Mercurial) : http://hg.dfrank.ru/vim/bundle/vimprj
Stable git repository: https://github.com/vim-scripts/vimprj (Note that this repository is auto-generated by http://vim-scripts.org as a mirror of http://www.vim.org)
|There's dependency: script-library DfrankUtil (vimscript #3884)
And i suggest you to use Pathogen (vimscript #2332) to manage your plugins.
Click on the package to download.
ip used for rating: 18.104.22.168
||I've published a thorough article on Vimprj + Indexer usage, you might want to check it out: http://dmitryfrank.com/articles/vim_project_code_navigation
New in this version:
- Added $VIMPRJ_PROJECT_ROOT variable, which is set to the root of the currently active project;
- Default behavior changed: now, by default, Vimprj doesn't touch your current working directory. Set g:vimprj_changeCurDirIfVimprjFound if you want it to do so.
||Fixed issue: there was an error if path contains spaces (thanks to Alexey Shevchenko)
||Fixed issue: if quickfix window is opened, and user compiles current file (types :make ), then vimprj swithed to the 'default' settings.
||* Please note: if you use plugin Indexer, then you need to update it to the latest version (4.15) because some hooks logic changed.
* Nested projects are supported, and added new hook "OnAfterSourcingVimprj". I would recommend you to read nice article by Francisco Lopes da Silva: http://goo.gl/vkCBc , there you can see well-explained example how to use these hooks effectively. Sorry for the lack of time to add all the hooks to docs. Great thanks to Francisco.
||*) Refactor. Added new dependency: script-library DfrankUtil (vimscript #3884)
||*) Added :VimprjInfo command that echoes current project root (project root is a directory which contains .vimprj directory or file)
*) Fix: new file creation is parsed correctly now.
||Added possibility to use just one file ".vimprj" (of course, name can be changed) instead of a whole directory, because in most cases people might want to create just one file with options, and ".vimprj/rc.vim" looks too obtrusive. Thanks to Aleksey Zapparov for nice remark.