History
Article Edit this page Discussion

Mkdir on edit if needed

From Vim Tips Wiki

Jump to: navigation, search

Tip 1529 Previous Next 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).

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

[edit] 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.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto Wiki
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Mkdir on edit if needed"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation