From 7d359d279c999c201d0ee794a60814205f084d63 Mon Sep 17 00:00:00 2001 From: surtur Date: Thu, 11 Aug 2022 12:33:20 +0200 Subject: [PATCH] vimrc: add automkdir func --- .vim/vimrc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.vim/vimrc b/.vim/vimrc index 206d313..3c0f955 100644 --- a/.vim/vimrc +++ b/.vim/vimrc @@ -935,6 +935,30 @@ hi CursorLineNR cterm=bold 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 ve :e $MYVIMRC nnoremap vr :source $MYVIMRC