projectroot


Ⅰ. 插件描述

Find out which project a file belongs to, easy to use in scripts/mappings

Ⅱ. 基本信息

创建日期:  2012-11-04
使用用户:  123
Github星:  98
插件作者:  Daan Bakker

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'dbakker/projectroot'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'dbakker/projectroot'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'dbakker/projectroot'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/dbakker/vim-projectroot

Ⅳ. 文档说明

Projectroot

There already are a ton of plugins (such as CtrlP) that try to guess what the
main project folder is of a file that you're working on, but this plugin allows
to easily re-use that functionality in your own custom mappings or scripts.

Features

  • Works out-of-the-box on most projects by detecting folders such as .git.
  • Very customizeable.
  • Easy to use in mappings and your own scripts, just use :ProjectRootCD or
    call ProjectRootGuess() to get the project root of the current file.
  • Can be combined easily with existing plugins. (see Examples)
  • Tries to be as lightweight as possible. For example, it only searches for
    a project root when a method such as ProjectRootGuess is used and does not
    automatically set any mappings or autocommands.

Installation

If you're using pathogen.vim execute:

cd ~/.vim/bundle
git clone git://github.com/dbakker/vim-projectroot.git

That's all!

However, to avoid having to type in long commands all the time, you will
probably want to set up some mappings. For this, check out the examples below or
consult [the
documentation](https://github.com/dbakker/vim-projectroot/blob/master/doc/projectroot.txt).

Examples

Change current working directory to project root

Using a mapping:

nnoremap <leader>dp :ProjectRootCD<cr>

Automatically whenever you open a buffer:

function! <SID>AutoProjectRootCD()
  try
    if &ft != 'help'
      ProjectRootCD
    endif
  catch
    " Silently ignore invalid buffers
  endtry
endfunction

autocmd BufEnter * call <SID>AutoProjectRootCD()

Grep

To grep with your project as base directory, you could add something like:

nnoremap <leader>g :ProjectRootExe grep<space>

Open file relative to the root

To start the command line with :e /my/path/to/project/, you could use this:

nnoremap <expr> <leader>ep ':edit '.projectroot#guess().'/'

NERDTree

If you would like NERDTree to always open at the root of your project, try
adding something like this to your vim config:

nnoremap <silent> <leader>dt :ProjectRootExe NERDTreeFind<cr>

Switching between files

These mappings might be handy to navigate between your project files.

nnoremap <silent> [p :ProjectBufPrev<cr>
nnoremap <silent> ]p :ProjectBufNext<cr>
nnoremap <silent> [P :ProjectBufFirst<cr>
nnoremap <silent> ]P :ProjectBufLast<cr>

To manage multiple projects, you could use something like:

nnoremap <silent> ]v :ProjectBufNext ~/.vim<cr>
nnoremap <silent> [v :ProjectBufPrev ~/.vim<cr>

Or if you had used mF to mark a file in a certain project:

nnoremap <silent> ]f :ProjectBufNext 'F<cr>
nnoremap <silent> [f :ProjectBufPrev 'F<cr>

Check out [the
documentation](https://github.com/dbakker/vim-projectroot/blob/master/doc/projectroot.txt)
for more information about the different commands and settings!

Similar projects

  • Vim Rooter: Changes the working
    directory to the project root when you open a file.
  • vimprj: Allows the execution of
    project or folder specific scripts.
  • CtrlP: Has an option to search
    for files relative to the root directory of your project.

License

Copyright (c) Daan O. Bakker. Distributed under the same terms as Vim itself.
See :help license.

添加新评论