Vim Tips Wiki
(New page: Category:File_Handling {{Tip |title=mkdir on edit if needed |created=2007/11/08 |complexity=intermediate |author=<!-- Your name or User:Name --> |version=<!-- minimal vim version ...)
 
(Insert TipProposed template + manual clean)
Line 1: Line 1:
  +
{{TipProposed
[[Category:File_Handling]]
 
  +
|id=0
 
  +
|previous=0
{{Tip
 
  +
|next=0
|title=mkdir on edit if needed
 
|created=2007/11/08
+
|created=November 8, 2007
 
|complexity=intermediate
 
|complexity=intermediate
  +
|author=Anon
|author=<!-- Your name or [[User:Name]] -->
 
  +
|version=7.0
|version=<!-- minimal vim version that can be used -->
 
 
}}
|text=
 
 
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). Wanted: versions for Windows/old Unices.
   
  +
<pre>
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). Wanted: versions for Windows/old Unices.
 
 
au BufNewFile * :exe ': !mkdir -p ' . escape(fnamemodify(bufname('%'),':p:h'),'#% \\')
  +
</pre>
   
 
==Comments==
au BufNewFile * :exe ': !mkdir -p ' . escape(fnamemodify(bufname('%'),':p:h'),'#% \\')
 
 
}}
 
   
  +
----
== Comments ==
 
 
[[Category:File Handling]]

Revision as of 04:02, 5 January 2008

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created November 8, 2007 · complexity intermediate · author Anon · 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). Wanted: versions for Windows/old Unices.

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

Comments