Skip to content

Commit 75c10bc

Browse files
azdanovmehalter
andauthored
feat(recipes): add additional information about rooter (#172)
* feat(recipes): add additional information about rooter * clarify autochdir and rooter difference * Update rooter.mdx * Improve language since `autochdir` is a rooter --------- Co-authored-by: Micah Halter <[email protected]>
1 parent 3462cb0 commit 75c10bc

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/content/docs/recipes/rooter.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,32 @@ return {
4343
},
4444
}
4545
```
46+
47+
## What is a "Rooter"?
48+
49+
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.
50+
51+
## Why Use a Rooter?
52+
53+
### The working directory in Neovim affects many operations:
54+
55+
- **File searching**: Tools like Telescope will search relative to your working directory
56+
- **Command execution**: Shell commands run from Neovim use the working directory as their context
57+
- **Project navigation**: Moving between files is easier when your working directory is at the project root
58+
59+
### Without a rooter, you might encounter these scenarios:
60+
61+
- Opening a file from a deeply nested directory makes it difficult to search for other project files
62+
- Moving between files in different parts of a project changes your context unpredictably
63+
- Running commands against your project requires manually changing directories
64+
65+
## AstroRoot vs. `autochdir`
66+
67+
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.
68+
69+
## Practical Use Cases:
70+
71+
- **Cross-project navigation**: When opening files from different projects, the rooter ensures your working context switches appropriately
72+
- **Telescope optimization**: Limits searches to the relevant project rather than including unrelated files
73+
- **Consistent command context**: Shell commands and LSP operations work against the proper project root
74+
- **Improved file navigation**: Makes it easier to navigate between related files in a project

0 commit comments

Comments
 (0)