Skip to content
Changes Vim working directory to project root (identified by presence of known directory or file).
Find file
Latest commit a3b9500 @airblade Update docs.
Failed to load latest commit information.
doc Update docs.
plugin Make root-finding publicly available.
.gitignore Added doc/tags to .gitignore
README.mkd Update docs.



Rooter is a Vim plugin which changes the working directory to the project root when you open a file.

The project root is identified by the presence of known directory, such as a VCS directory, or file, such as a Rakefile. Out of the box it looks for git, darcs, mercurial, bazaar, and subversion, but you can configure it to look for anything you like.


By default you don't need to do anything: vim-rooter will change the working directory automatically and echo the new working directory.

vim-rooter will unset &autochdir if it's set because the plugin supersedes the option's functionality.

You can always invoke vim-rooter manually with <Leader>cd.

Using root-finding functionality in other scripts

The public function FindRootDirectory() returns the absolute path to the root directory as a string, if a root directory is found, or an empty string otherwise.

If that's all you need from this plugin, you can turn off the rest of its behaviour like this:

let g:rooter_manual_only = 1
let g:rooter_disable_map = 1


You can change the manual-invocation mapping by adding this to your .vimrc:

map <silent> <unique> <Leader>foo <Plug>RooterChangeToRootDirectory

where <Leader>foo is the mapping you want.

To prevent vim-rooter from creating a mapping, do this:

let g:rooter_disable_map = 1

By default all files trigger vim-rooter. You can restrict the files by passing a comma separated list of extensions, like this:

let g:rooter_autocmd_patterns = '*.rb,*.haml,*.js'

To stop vim-rooter changing directory automatically, add this to your .vimrc:

let g:rooter_manual_only = 1

You can set your own directory and file patterns like this:

let g:rooter_patterns = ['Rakefile', '.git/']

Vim-rooter checks the patterns depth-first in the order given. So to work correctly with git submodules you should have .git before .git/. All directories should have a trailing slash.

Setting your own patterns overwrites the defaults. You can use

let g:rooter_patterns = g:rooter_patterns + [ 'foo' ]

to append to the default patterns.

You can have vim-rooter locally change directory (:lcd) instead of changing directory (:cd) by adding this to your .vimrc:

let g:rooter_use_lcd = 1

When vim-rooter encounters a non-project file, it won't change directory by default. If you would instead like vim-rooter to change to the file's directory, do this:

let g:rooter_change_directory_for_non_project_files = 1

This makes vim-rooter behave similarly to autochdir for non-project files.

If you don't want vim-rooter to echo the project directory, try this:

let g:rooter_silent_chdir = 1


Install into ~/.vim/plugin/rooter.vim or, if you're using Pathogen, into ~/.vim/bundle/rooter.vim.

Something went wrong with that request. Please try again.