How to make a new directory and a file in Vim

Switch to file browsing mode

:Ex or if that is not working use :Explore

then press

d

and add the new directory name.


If you are in the file explorer mode, you can use:

d for creating a directory

% for creating a new file

In explorer mode you can get with issuing a command :Sexplore or :Vexplore

There is no need to call external commands with !


Assuming you're running a shell, I would shell out for either of these commands. Enter command mode with Esc, and then:

:! touch new-file.txt
:! mkdir new-directory

A great plugin for these actions is vim-eunuch, which gives you syntactic sugar for shell commands. Here's the latter example, using vim-eunuch:

:Mdkir new-directory

Tags:

Vim