34 lines
1.1 KiB
Plaintext
34 lines
1.1 KiB
Plaintext
function! s:MkNonExDir(file, buf)
|
|||
|
|
if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
|
||
|
|
let dir=fnamemodify(a:file, ':h')
|
||
|
|
if !isdirectory(dir)
|
||
|
|
call mkdir(dir, 'p')
|
||
|
|
endif
|
||
|
|
endif
|
||
|
|
endfunction
|
||
|
|
augroup BWCCreateDir
|
||
|
|
autocmd!
|
||
|
|
autocmd BufWritePre * :call s:MkNonExDir(expand('<afile>'), +expand('<abuf>'))
|
||
|
|
augroup END
|
||
|
|
|
||
|
|
function! Indenting(indent, what, cols)
|
||
|
|
let spccol = repeat(' ', a:cols)
|
||
|
|
let result = substitute(a:indent, spccol, '\t', 'g')
|
||
|
|
let result = substitute(result, ' \+\ze\t', ''', 'g')
|
||
|
|
if a:what == 1
|
||
|
|
let result = substitute(result, '\t', spccol, 'g')
|
||
|
|
endif
|
||
|
|
return result
|
||
|
|
endfunction
|
||
|
|
|
||
|
|
function! IndentConvert(line1, line2, what, cols)
|
||
|
|
let savepos = getpos('.')
|
||
|
|
let cols = empty(a:cols) ? &tabstop : a:cols
|
||
|
|
execute a:line1 . ',' . a:line2 . 's/^\s\+/\=Indenting(submatch(0), a:what, cols)/e'
|
||
|
|
call histdel('search', -1)
|
||
|
|
call setpos('.', savepos)
|
||
|
|
endfunction
|
||
|
|
command! -nargs=? -range=% Space2Tab call IndentConvert(<line1>,<line2>,0,<q-args>)
|
||
|
|
command! -nargs=? -range=% Tab2Space call IndentConvert(<line1>,<line2>,1,<q-args>)
|
||
|
|
command! -nargs=? -range=% RetabIndent call IndentConvert(<line1>,<line2>,&et,<q-args>)
|