Fandom

Vim Tips Wiki

Mkdir on edit if needed

Redirected from VimTip1529

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Tip 1529 Printable Monobook Previous Next

created 2007 · complexity intermediate · version 7.0


When opening a new file with :edit or :split, you may want to create the directory the file will reside in. This can be done in autocommand BufNewFile (add to vimrc in any Unix-like system with mkdir that accepts -p switch).

au BufNewFile * :exe ': !mkdir -p ' . escape(fnamemodify(bufname('%'),':p:h'),'#% \\')

CommentsEdit

 TO DO 
This tip is rather dodgy for those of us who sometimes make mistakes. I don't think it should automatically create possibly several directories as a result of a simple typo in the :edit /path/file command.

The tip should instead provide a specific command to create a path and edit a file (you would know that using the command may create unwanted directories if you made a typo).

I believe that the md/mkdir in any Windows with cmd.exe (possibly not NT4) will make intermediate directories without needing -p or any other option.


Also on Fandom

Random Wiki