vimrc: add automkdir func
This commit is contained in:
parent
0510f85823
commit
7d359d279c
24
.vim/vimrc
24
.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 <Leader>ve :e $MYVIMRC<CR>
|
||||
nnoremap <Leader>vr :source $MYVIMRC<CR>
|
||||
|
Loading…
Reference in New Issue
Block a user