9

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.

9

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.

3

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.