reset indent if the line starts with syntax
note: | is cursor snippet a options| type space, then above code become snippet a options |
This commit is contained in:
parent
1bd7e23c79
commit
ea693eebb0
@ -35,28 +35,48 @@ set cpo&vim
|
|||||||
if !exists('b:undo_indent')
|
if !exists('b:undo_indent')
|
||||||
let b:undo_indent = ''
|
let b:undo_indent = ''
|
||||||
else
|
else
|
||||||
let b:undo_indent = '|'
|
let b:undo_indent .= '|'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
setlocal autoindent
|
||||||
setlocal indentexpr=SnippetsIndent()
|
setlocal indentexpr=SnippetsIndent()
|
||||||
|
setlocal indentkeys=o,O,=abbr\ ,=prev_word\ ,=alias\ ,=options\ ,=regexp\ ,!^F
|
||||||
|
|
||||||
|
let b:undo_indent .= 'setlocal
|
||||||
|
\ autoindent<
|
||||||
|
\ indentexpr<
|
||||||
|
\ indentkeys<
|
||||||
|
\'
|
||||||
|
|
||||||
function! SnippetsIndent() abort "{{{
|
function! SnippetsIndent() abort "{{{
|
||||||
let line = getline('.')
|
let line = getline('.')
|
||||||
let prev_line = (line('.') == 1)? '' : getline(line('.')-1)
|
let prev_line = (line('.') == 1)? '' : getline(line('.')-1)
|
||||||
let syntax = '\%(include\|snippet\|abbr\|prev_word\|delete\|alias\|options\|regexp\)'
|
let syntax = '\%(include\|snippet\|abbr\|prev_word\|delete\|alias\|options\|regexp\)\s'
|
||||||
|
let defining = '\%(snippet\|abbr\|prev_word\|alias\|options\|regexp\)\s'
|
||||||
|
|
||||||
if prev_line =~ '^\s*$'
|
"for indentkeys o,O
|
||||||
|
if s:is_empty(line)
|
||||||
|
if s:is_empty(prev_line)
|
||||||
return 0
|
return 0
|
||||||
elseif prev_line =~ '^' . syntax && line !~ '^\s*' . syntax
|
elseif prev_line =~ '^' . defining
|
||||||
return shiftwidth()
|
return shiftwidth()
|
||||||
else
|
else
|
||||||
return match(line, '\S')
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
"for indentkeys =words
|
||||||
|
else
|
||||||
|
if line =~ '^\s*' . syntax
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
let b:undo_indent .= '
|
function! s:is_empty(line)
|
||||||
\ setlocal indentexpr<
|
return a:line =~ '^\s*$'
|
||||||
\'
|
endfunction
|
||||||
|
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
unlet s:save_cpo
|
unlet s:save_cpo
|
||||||
|
Loading…
Reference in New Issue
Block a user