Creating files and directories

4.5
(56)

Vim’s built in file browser, netrw, has a multitude of uses. One oft-overlooked capability is the ability to create files and folders from inside its directory view. Without netrw, I’d need to use:

  • !mkdir path/to/dir – Make new directories by shelling out
  • :e path/to/dir/file.txt – Open a new buffer at the file path

But netrw gives us a better way and it works from any directory view. I usually open Vim with vim . which pops me right into the netrw view. From here, I can create new files or directories:

  • % – Create new file from netrw
  • d – Create new directory from netrw

If you’re in a buffer and want to hop back to the file tree, just use :e . and you’ll be placed in a view of the current working directory. From here, you can browse and create a new file or folder exactly where you want it.

How useful was this tip?

Average rating 4.5 / 5. Vote count: 56

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts