There are many ways to create a new file or directory in vim tho. Either vanilla UNIX Shell command, with vim itself, or with the plugin. We will go through all of these.
UNIX Shell command
First, you need to enter command mode with
ESC, and then;
:! touch new-file.txt :! mkdir new-directory
These will create the directory and file in CURRENT working directory, which is the directory when you started your current vim process in the beginning.
When in doubt, always use
:!pwd to check your current working directory.
A great plugin for these actions is vim-eunuch, which gives you a lot of sugar for the UNIX shell commands. Here's the latter example, using
same as step 1, but easier to type. There is no need to call external commands with
Explore mode is really cool. There are two ways two open
Explore mode. Type one of these commands;
:Sexplore, it will be like this;
:Explore, it will be like this;
The difference is where the
explore mode opens. You need to choose one that is better for you.
note: I'm using the NERDTree plugin.
Then, you can easily navigate to whatever sub-directory you like by ;
kto move the cursor
Enterto enter a sub-directory
-to go up a level of directory
Now, you can type;
dto create a directory
%to create a file
This is my favorite because I am using NERDTree for my Neovim setup. Follow these step;
- Navigate to the directory where you want to create the new file/directory.
mto bring up the NERDTree Filesystem Menu. This menu allows you to create, rename, and delete files and directories. It will be like this;
ato add a child node and then simply enter the filename.
- You’re done! 🥳
note: To create a directory follow the same steps but append a
/to the filename.
That is why I love this step.
Top comments (2)
I have a problem with NERDTree in Windows in remove folders, NT show this message log:
NERDTree: could not remove node
Someone can help to solve this error?
cool ! thanks for sharing it works. I also use neovim and nerdtree