Make new folder from Vim command line in Windows gVim

gvimvim

Can it be done?

I am editing a file, and I would like to copy it to a new folder. If I try :w ~/Documents/new_folder/new_file.txt, then I get Can't open file for writing.

So I try :!mkdir ~/Documents/new_folder, but I get the error (in a popup terminal window):

C:\Windows\system32\cmd.exe /c mkdir ~/Documents/new_folder
The syntax of the command is incorrect.
shell returned 1
Hit any key to close this window...

What am I missing? Thanks!

Best Answer

Windows gvim uses Windows' cmd.exe to execute :! commands and cmd.exe does not understand ~ as an alias for $HOME. Also, cmd.exe accepts only \ as a path separator, not /. Try instead

:cd ~
:!mkdir Documents\new_folder

Since :cd is a Vim internal command, Vim will correctly expand ~ itself.

[Edit: Added ! in front of mkdir (typo), changed path separator from / to \ (mistake) and added sentence about it.]