From 116e869e24023d3f4d670da19ed0dadb7063bfcc Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 27 Oct 2017 20:45:59 -0400 Subject: this should also be a plugin --- vimrc | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'vimrc') diff --git a/vimrc b/vimrc index d49f108..aa8e553 100644 --- a/vimrc +++ b/vimrc @@ -92,34 +92,6 @@ augroup END " When editing a file, always jump to the last cursor position {{{ autocmd vimrc BufReadPost * if line("'\"") <= line("$") | exe "normal! g`\"" | endif " }}} -" Prompt to create directories if they don't exist {{{ -autocmd vimrc BufNewFile * :call ensure_dir_exists() -function! s:ensure_dir_exists () - let l:required_dir = expand("%:h") - if !isdirectory(l:required_dir) - if ask_quit("Directory '" . l:required_dir . "' doesn't exist.", "&Create it?") - return - endif - - try - call mkdir( l:required_dir, 'p' ) - catch - call ask_quit("Can't create '" . l:required_dir . "'", "&Continue anyway?") - endtry - endif -endfunction -function! s:ask_quit (msg, proposed_action) - if confirm(a:msg, "&Quit?\n" . a:proposed_action) == 1 - if len(getbufinfo()) > 1 - silent bd - return 1 - else - exit - end - endif - return 0 -endfunction -" }}} " }}} " bindings {{{ " general {{{ @@ -518,5 +490,33 @@ endfor inoremap ' strpart(getline('.'), col('.')-1, 1) == "\'" ? "\=\move_cursor_right()?'':''\" : col('.') == 1 \|\| match(strpart(getline('.'), col('.')-2, 1), '\W') != -1 ? "\'\'\=\move_cursor_left()?'':''\" : "\'" inoremap " strpart(getline('.'), col('.')-1, 1) == '"' ? "\=\move_cursor_right()?'':''\" : "\"\"\=\move_cursor_left()?'':''\" " }}} +" Prompt to create directories if they don't exist {{{ +autocmd vimrc BufNewFile * :call ensure_dir_exists() +function! s:ensure_dir_exists () + let l:required_dir = expand("%:h") + if !isdirectory(l:required_dir) + if ask_quit("Directory '" . l:required_dir . "' doesn't exist.", "&Create it?") + return + endif + + try + call mkdir( l:required_dir, 'p' ) + catch + call ask_quit("Can't create '" . l:required_dir . "'", "&Continue anyway?") + endtry + endif +endfunction +function! s:ask_quit (msg, proposed_action) + if confirm(a:msg, "&Quit?\n" . a:proposed_action) == 1 + if len(getbufinfo()) > 1 + silent bd + return 1 + else + exit + end + endif + return 0 +endfunction +" }}} " }}} " vim: fdm=marker -- cgit v1.2.3-54-g00ecf