How do I open netrw in a left sidebar rooted at the current file's directory?
Answer
:Lexplore %:p:h
Explanation
When you are editing deep in a project, opening netrw from the working directory often puts you in the wrong place. This command opens netrw as a left explorer sidebar and starts it in the directory of the current file, which is faster for nearby file hops. It is a good built-in alternative when you want lightweight file browsing without external tree plugins.
How it works
:Lexplore %:p:h
:Lexploreopens netrw in a left-side split and toggles that explorer window%expands to the current buffer's file name:pconverts it to a full absolute path:htakes the head directory portion of that path- Combined,
%:p:hresolves to the current file's parent directory
This avoids changing your global working directory and keeps your current editing window focused while giving you a local navigation panel.
Example
Suppose your current file is:
/home/finn/src/app/internal/server/handlers.go
Running :Lexplore %:p:h opens netrw on:
/home/finn/src/app/internal/server
From there you can quickly open sibling files such as routes.go or middleware.go.
Tips
- Run
:Lexploreagain to close the sidebar - Use
:Vexplore %:p:hif you prefer a right-side explorer split