Wikia

Vim Tips Wiki

Changes: Mkdir on edit if needed

Edit

Back to page

(change "anon" author to blank; trim "created" date; minor manual clean)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 3: Line 3:
 
|previous=1526
 
|previous=1526
 
|next=1530
 
|next=1530
|created=November 8, 2007
+
|created=2007
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=
 
|author=
Line 11: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
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).
+
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).
 
<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 <tt>:edit /path/file</tt> 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 <code>:edit /path/file</code> 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 <tt>-p</tt> 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 <code>-p</code> or any other option.
   
 
----
 
----

Latest revision as of 06:30, July 13, 2012

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.


Around Wikia's network

Random Wiki