Created
February 3, 2022 16:21
-
-
Save PeterRincker/80b80ff5e55f0489fc484d6fe201d4fa to your computer and use it in GitHub Desktop.
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
" create parent directories | |
" http://stackoverflow.com/questions/4292733/vim-creating-parent-directories-on-save | |
function! s:MkNonExDir(file, buf) | |
if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/' | |
let dir=fnamemodify(a:file, ':h') | |
if !isdirectory(dir) | |
call mkdir(dir, 'p') | |
endif | |
endif | |
endfunction | |
augroup BWCCreateDir | |
autocmd! | |
autocmd BufWritePre * :call s:MkNonExDir(expand('<afile>'), +expand('<abuf>')) | |
augroup END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment