Ⅰ. 插件描述
Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'lucapette/vim-rootfinder'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'lucapette/vim-rootfinder'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'lucapette/vim-rootfinder'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/lucapette/vim-rootfinder
Ⅳ. 文档说明
This Vim plugin makes sense for you only if set autochdir is part of your
workflow.
I noticed that some plugins make the assumption you have to start Vim in your
current working directory. I mean stuff like Ack.vim for example. I always
make the assumption that the current working directory is the one of the
current buffer since I use set autochdir. Of course using the option makes
harder to reach your project directory for searching project-wise or for open
an :Explore.
How it works
The plugin adds a rootfinder#current() function to your runtime. The
function returns your current directory based on the following rules:
- When The buffer you're editing is in a sub-directory of one of your code
directories then your current root will be the first sub-directory of your
current code directory. Examples (with /tmp/code as one of the code directories):
| Buffer | rootfinder#current() |
| /tmp/awesome-project/foo.rb | /tmp/code/awesome-project |
| /tmp/code/code/super-project/foo/bar.rb | /tmp/code/super-project |
| /any/path/but/not/foo.rb | /any/path/but/not/ |
- When the buffer you're editing is not in one of your code directories the
current root will be the nearest ancestor that contains a specific file. See
the options section about how to use it.
- When none of the previous rules applies than the
rootfinder#current()will
simply return the current directory of the file you're editing.
Options
You can specify your code directories in the following way:
let g:rootfinder_code_dirs = ['/home/lucapette/code', '/home/lucapette/Dropbox/experiments']
The default value is [$HOME.'/code']
You can specify your root directory using markers:
let g:rootfinder_markers = ['.git', '.root_dir']
The default value is ['.git', '.hg', '.svn', '.bzr', '_darcs']. This feature
is heavily inspired (stolen) from ctrlp.vim.
Installation
I strongly recommend installing pathogen.vim.
cd ~/.vim/bundle
git clone git://github.com/lucapette/vim-rootfinder.git
Or you can unzip it in your ~/.vim directory.
Use cases
You could use `rootfinder#current() for plugins like NERDTree:
nnoremap <silent> <F4> :NERDTreeToggle <C-R>=rootfinder#current()>CR><CR>
The same thing with the CommandT plugin in the following way:
map <silent> <C-T> :CommandT <C-R>rootfinder#current()<CR><CR>
Copyright
Copyright (c) Luca Pette. Distributed under the same terms as Vim itself.
