Use Mkdir! to create dir of present file in vim
In vim its easy to :edit
, :write
, or :saveas
a file to a path that doesn't yet exist. Such as:
:edit non/existant/path/file.txt
Vim will let you have a buffer with that path, but when you try to write the file vim will throw an error:
E212: Can't open file for writing
Enter the Mkdir!
command. The Mkdir
command has been added by the eunuch.vim plugin to make creating directories easier from vim. The bang (!) variant takes the path of the current buffer and creates the directory from that path.
When we get the E212 error we can type:
:Mkdir!
And walla! The path will be created. No more errors when writing the file.
Tweet