vimtricks.wiki Concise Vim tricks, one at a time.

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
  • :Lexplore opens netrw in a left-side split and toggles that explorer window
  • % expands to the current buffer's file name
  • :p converts it to a full absolute path
  • :h takes the head directory portion of that path
  • Combined, %:p:h resolves 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 :Lexplore again to close the sidebar
  • Use :Vexplore %:p:h if you prefer a right-side explorer split

Next

How do I launch a GDB session in Vim with the built-in termdebug plugin?