Vim Tips Wiki
Register
(Adjust previous/next navigation)
(change "anon" author to blank; trim "created" date; minor manual clean)
Line 5: Line 5:
 
|created=November 8, 2007
 
|created=November 8, 2007
 
|complexity=intermediate
 
|complexity=intermediate
|author=Anon
+
|author=
 
|version=7.0
 
|version=7.0
 
|subpage=/200712
 
|subpage=/200712

Revision as of 03:02, 4 December 2009

Tip 1529 Printable Monobook Previous Next

created November 8, 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'),'#% \\')

Comments

 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.