Created
November 5, 2022 22:46
-
-
Save omar2205/aca4aea04f96924ed8bf35a3818eded4 to your computer and use it in GitHub Desktop.
Vim create a dir if it's doesn't exist
This file contains hidden or 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
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