vimrc: add automkdir func

This commit is contained in:
surtur 2022-08-11 12:33:20 +02:00
parent 0510f85823
commit 7d359d279c
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

@ -935,6 +935,30 @@ hi CursorLineNR cterm=bold
syntax sync minlines=256 syntax sync minlines=256
function! AskQuit (msg, proposed_action)
if confirm(a:msg, "&Quit?\n" . a:proposed_action) == 1
exit
endif
endfunction
function! EnsureDirExists ()
let required_dir = expand('%:h')
if !isdirectory(required_dir)
call AskQuit('Directory "' . required_dir . '" doesn''t exist.', '&Create it?')
try
call mkdir( required_dir, 'p' )
catch
call AskQuit('Can''t create "' . required_dir . '"', '&Continue anyway?')
endtry
endif
endfunction
augroup AutoMkdir
autocmd!
autocmd BufNewFile * :call EnsureDirExists()
augroup END
nnoremap <Leader>ve :e $MYVIMRC<CR> nnoremap <Leader>ve :e $MYVIMRC<CR>
nnoremap <Leader>vr :source $MYVIMRC<CR> nnoremap <Leader>vr :source $MYVIMRC<CR>