Created
April 4, 2011 15:46
-
-
Save majutsushi/901860 to your computer and use it in GitHub Desktop.
Automatically create dir to write file to if it doesn't exist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Automatically create dir to write file to if it doesn't exist | |
function! AutoMkDir() | |
let required_dir = expand("<afile>:p:h") | |
if !isdirectory(required_dir) | |
if confirm("Directory '" . required_dir . "' doesn't exist.", "&Abort\n&Create it") != 2 | |
bdelete | |
return | |
endif | |
try | |
call mkdir(required_dir, 'p') | |
catch | |
if confirm("Can't create '" . required_dir . "'", "&Abort\n&Continue anyway") != 2 | |
bdelete | |
return | |
endif | |
endtry | |
endif | |
endfunction | |
autocmd BufNewFile,BufWritePre * call AutoMkDir() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment