Advertisement
Guest User

automkdir.vim

a guest
Aug 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 0.45 KB | None | 0 0
  1. if exists('g:automkdir_loaded')
  2.     finish
  3. endif
  4. let g:automkdir_loaded = 1
  5.  
  6. function! s:MkNonExDir(file, buf)
  7.     if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
  8.         let dir=fnamemodify(a:file, ':h')
  9.         if !isdirectory(dir)
  10.             call mkdir(dir, 'p')
  11.         endif
  12.     endif
  13. endfunction
  14. augroup BWCCreateDir
  15.     autocmd!
  16.     autocmd BufWritePre * :call s:MkNonExDir(expand('<afile>'), +expand('<abuf>'))
  17. augroup END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement