Is it possible to edit a directory inside Vim? (Some commands are working for directories).

I want to know what kind of operations can be done in a directory inside Vim. Vim can open the directories for editing, I believe it will have commands also to work with. But usual commands behave differently for directories.

For example, pressing I and typing a filename and saving the directory. When I give ls, it should show that file.

  • I would love the ability to rename files when viewing a directory listing as a text file. I don't see anything out there :( Aug 28 '20 at 4:19

I'm assuming you are using netrw here, as it's the default action when you do vim . or vim some/directory/.

You can create a file/directory from netrw with the following commands:

d : create a directory, you will be prompted to input the directory name
% : create a file, same workflow

Have a look at :h netrw for more informations.


Totally a different angle, but it works without having to install any plugins ...

When I want to create or rename a directory from a running Vim session, I'll simply type :! followed by the appropriate shell command, doing something like the following:

For Linux

  • :! mkdir newdir to create a directory
  • :! mv newdir renamed_dir to rename a directory

For Windows

  • :! mkdir newdir to create a directory
  • :! move newdir renamed_dir to rename a directory

As far as I know, you can literally execute whatever shell command you like this way without having to exit from Vim or having to open a separate terminal window.

  • Thanks. but I am not asking about shell commands. I want to explore the options related to editing directory, like we edit a file.
    – SibiCoder
    May 5 '16 at 13:44
  • 2
    It's worth knowing the github.com/tpope/vim-eunuch plugin also.
    – nobe4
    May 5 '16 at 13:51
  • 1
    +1 for not reinventing the wheel
    – Insane
    May 5 '16 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.