Vim Tips Wiki
Register
We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 3: Line 3:
 
|previous=1526
 
|previous=1526
 
|next=1530
 
|next=1530
|created=2007
+
|created=November 8, 2007
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=
 
|author=
Line 11: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
When opening a new file with <code>:edit</code> or <code>:split</code>, 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).
+
When opening a new file with <tt>:edit</tt> or <tt>:split</tt>, 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).
 
<pre>
 
<pre>
 
au BufNewFile * :exe ': !mkdir -p ' . escape(fnamemodify(bufname('%'),':p:h'),'#% \\')
 
au BufNewFile * :exe ': !mkdir -p ' . escape(fnamemodify(bufname('%'),':p:h'),'#% \\')
Line 18: Line 18:
 
==Comments==
 
==Comments==
 
{{Todo}}
 
{{Todo}}
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 <code>:edit /path/file</code> command.
+
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 <tt>:edit /path/file</tt> 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).
 
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 <code>-p</code> or any other option.
+
I believe that the md/mkdir in any Windows with cmd.exe (possibly not NT4) will make intermediate directories without needing <tt>-p</tt> or any other option.
   
 
----
 
----
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel Editing help (opens in new window)