codepath plugin for vim
Hi everyone,
Recently I have written a plugin for vim, the most awesome editor ever created. It is a simple plugin but I find it extremely useful. You can find it on vim site or on github. I have extracted the following text from the codepath.vim documentation: codepath.vim is a plugin that provides a simple function to obtain your code path directory if you have one. The concept is simple: I have a dir located in $HOME/code where I store all my projects and I want to set current project directory as root directory for plug-in like NERDTree and FuzzyFinderTextMate.
To understand better what I mean, please consider the following examples:
| File Opened | CodePath() Result |
| codepath/awesome-project/foo.rb | codepath/awesome-project |
| codepath/code/super-project/foo/bar.rb | codepath/super-project |
| /any/path/but/not/code/foo.rb | /any/path/but/not/code |
So, the CodePath Function returns the project root if you open a file in any subdirectory of your codepath and returns the directory itself if you open a file in any other location. At the moment the only configuration available is the codepath directory location. You can set it in the following way:
let g:codepath = “/your/dir”
If you don’t set g:codepath the codepath.vim will consider $HOME/code as your codepath directory. In my vim configuration (you can find it here), I use the CodePath function in the following way in my vimrc:
nnoremap <silent> <F4> :NERDTreeToggle `=CodePath()`<cr>
inoremap <silent> <F4> <Esc>:NERDTreeToggle `=CodePath()` <cr>
Every time I open a NERDTree window It opens itself based on my function. I did the same thing with the FuzzyFinder plugin in the following way:
let g:fuzzy_roots = [CodePath()]
I think codepath.vim is a really simple vim plugin and it is really useful for me, I hope you can use it in your vim configuration. I haven’t planned new features yet but I will add the multi-codepath feature if I receive feedback on it.