Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Project Root

Linwei edited this pageApr 28, 2018 ·19 revisions

Vim is lack of project management, as files usually belong to projects, you can do nothing to the project if you don't have any information about where the project locates. Inspired by CtrlP, this feature (new in version 1.3.12) is very useful when you've something to do with the whole project.

Macro<root> or$(VIM_ROOT) in the command line or in the-cwd option will be expanded as theProject Root Directory of the current file:

:AsyncRunmake:AsyncRun -cwd=<root>make

The first command will runmake in the current directory of vim (which:pwd returns), while the second one will runmake in the project root directory of current file.

:AsyncRun -cwd=<root>grep-n-R sendto .:AsyncRun -cwd=<root>grep-n-R--include=*.c--include=*.cpp--include=*.h sendto .

These commands above will change the working directory to the project root of the current file, and grep the keywordsendto in the given ext-names.

TheProject Root is the nearest ancestor directory of the current file which contains one of these directories or files:

.svn .git .hg .root .project

If none of the parent directories contains theseroot markers, the directory of the current file is used as the project root. If your current project is not in any git or subversion repository, just put an empty .root file in your project root, AsyncRun will take it as the project root.

Config Root Markers

The default root markers can also be changed by optiong:asyncrun_rootmarks:

:let g:asyncrun_rootmarks = ['.svn', '.git', '.root', '.bzr', '_darcs', 'build.xml']

When you are using-cwd=<root>, remember to use$(VIM_XXX) macros instead of% macros because% macros will be expanded by vim itselfbefore changing directory while$(VIM_XXX) will be expandedafter changing directory.

Incorrect usage:

:AsyncRun -cwd=<root> gcc%-o%<

Correct way:

:AsyncRun -cwd=<root> gcc$(VIM_RELDIR)/$(VIM_FILENAME) -o $(VIM_RELDIR)/$(VIM_FILENOEXT)

These macros can also be used in the command line:

:AsyncRunmake-f$(VIM_ROOT)/Makefile:AsyncRun svnup$(VIM_ROOT)

Manually set the project root

Use buffer variables to indicate the project root manually for a given file:

:letb:asyncrun_root="/xxxx/path-to-the-project-root"

Find project root outside asyncrun

This will print the project root of current file:

:echoasyncrun#get_root('%')
Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp