diff options
author | Jesse Luehrs <doy@tozt.net> | 2017-10-27 20:45:59 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2017-10-27 20:46:07 -0400 |
commit | 116e869e24023d3f4d670da19ed0dadb7063bfcc (patch) | |
tree | bdfc62950b4b251d28fee2727cee2a83347b038a /vimrc | |
parent | 3839eb947fdb6c7bfeccbcd594db2a966ede6293 (diff) | |
download | conf-116e869e24023d3f4d670da19ed0dadb7063bfcc.tar.gz conf-116e869e24023d3f4d670da19ed0dadb7063bfcc.zip |
this should also be a plugin
Diffstat (limited to 'vimrc')
-rw-r--r-- | vimrc | 56 |
1 files changed, 28 insertions, 28 deletions
@@ -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 <SID>ensure_dir_exists() -function! s:ensure_dir_exists () - let l:required_dir = expand("%:h") - if !isdirectory(l:required_dir) - if <SID>ask_quit("Directory '" . l:required_dir . "' doesn't exist.", "&Create it?") - return - endif - - try - call mkdir( l:required_dir, 'p' ) - catch - call <SID>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 <silent><expr> ' strpart(getline('.'), col('.')-1, 1) == "\'" ? "\<C-R>=\<SID>move_cursor_right()?'':''\<CR>" : col('.') == 1 \|\| match(strpart(getline('.'), col('.')-2, 1), '\W') != -1 ? "\'\'\<C-R>=\<SID>move_cursor_left()?'':''\<CR>" : "\'" inoremap <silent><expr> " strpart(getline('.'), col('.')-1, 1) == '"' ? "\<C-R>=\<SID>move_cursor_right()?'':''\<CR>" : "\"\"\<C-R>=\<SID>move_cursor_left()?'':''\<CR>" " }}} +" Prompt to create directories if they don't exist {{{ +autocmd vimrc BufNewFile * :call <SID>ensure_dir_exists() +function! s:ensure_dir_exists () + let l:required_dir = expand("%:h") + if !isdirectory(l:required_dir) + if <SID>ask_quit("Directory '" . l:required_dir . "' doesn't exist.", "&Create it?") + return + endif + + try + call mkdir( l:required_dir, 'p' ) + catch + call <SID>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 |