Skip to content

feat(recipes): add additional information about rooter #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/content/docs/recipes/rooter.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,32 @@ return {
},
}
```

## What is a "Rooter"?

A rooter automatically changes Neovim's working directory based on the context of your current file. Instead of staying in the directory where you launched Neovim, it can detect and switch to the root of your project. This concept has been popular in the Vim ecosystem for many years with the `autochdir` option, and with plugins like [vim-rooter](https://github.com/airblade/vim-rooter) being among the first implementations.

## Why Use a Rooter?

### The working directory in Neovim affects many operations:

- **File searching**: Tools like Telescope will search relative to your working directory
- **Command execution**: Shell commands run from Neovim use the working directory as their context
- **Project navigation**: Moving between files is easier when your working directory is at the project root

### Without a rooter, you might encounter these scenarios:

- Opening a file from a deeply nested directory makes it difficult to search for other project files
- Moving between files in different parts of a project changes your context unpredictably
- Running commands against your project requires manually changing directories

## AstroRoot vs. `autochdir`

Neovim has a built-in autochdir option that automatically changes the working directory to match the current file's directory. However, this is rarely ideal for project work, since `autochdir` always sets the directory to the file's immediate parent directory. This feature aims to intelligently find the project root, which can be several levels up from individual files by applying more rules for detecting the root of the project.

## Practical Use Cases:

- **Cross-project navigation**: When opening files from different projects, the rooter ensures your working context switches appropriately
- **Telescope optimization**: Limits searches to the relevant project rather than including unrelated files
- **Consistent command context**: Shell commands and LSP operations work against the proper project root
- **Improved file navigation**: Makes it easier to navigate between related files in a project