Improved the math mapping structure
This commit is contained in:
parent
01e832d019
commit
91942ceb25
@ -79,26 +79,39 @@ function! vimtex#mappings#init(initialized) " {{{1
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let ultisnip_maps = [
|
let g:vimtex_mappings = [
|
||||||
\ ['__', '_\{$1\}'],
|
\ { 'lhs' : '__', 'rhs' : '_\{$1\}', 'math' : 1, 'type' : 'map'},
|
||||||
\ ['^^', '^\{$1\}'],
|
\ { 'lhs' : '^^', 'rhs' : '^\{$1\}', 'math' : 1, 'type' : 'map'},
|
||||||
\ ['((', '\left($1\right)'],
|
\ { 'lhs' : '((', 'rhs' : '\left($1\right)', 'math' : 1, 'type' : 'map'},
|
||||||
\ ['[[', '\left[$1\right]'],
|
\ { 'lhs' : '[[', 'rhs' : '\left[$1\right]', 'math' : 1, 'type' : 'map'},
|
||||||
|
\ { 'lhs' : '`a', 'rhs' : '\alpha', 'math' : 1, 'type' : 'abbrev'},
|
||||||
\]
|
\]
|
||||||
for [lhs, rhs] in ultisnip_maps
|
|
||||||
silent execute 'inoremap <buffer><silent>' lhs
|
|
||||||
\ lhs . '<c-r>=UltiSnips#Anon(''' . rhs . ''', ''' . lhs
|
|
||||||
\ . ''', '''', ''i'')<cr>'
|
|
||||||
endfor
|
|
||||||
|
|
||||||
let abbreviations = [
|
call s:init_math_mappings()
|
||||||
\ ['`a', '\alpha'],
|
endfunction
|
||||||
\]
|
|
||||||
for [lhs, rhs] in abbreviations
|
" }}}1
|
||||||
silent execute 'iabbrev <buffer>' lhs rhs
|
|
||||||
|
function! s:init_math_mappings() " {{{1
|
||||||
|
for map in g:vimtex_mappings
|
||||||
|
if map.type ==# 'map'
|
||||||
|
silent execute 'inoremap <buffer><silent>' map.lhs
|
||||||
|
\ map.lhs . '<c-r>=UltiSnips#Anon(''' . map.rhs . ''', ''' . map.lhs
|
||||||
|
\ . ''', '''', ''i'')<cr>'
|
||||||
|
elseif map.type ==# 'abbrev'
|
||||||
|
silent execute 'inoremap <silent><buffer> ' . map.lhs
|
||||||
|
\ . ' <c-r>=<sid>is_math() ?'
|
||||||
|
\ string(map.rhs) ':' string(map.lhs) '<cr>'
|
||||||
|
endif
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" }}}1
|
||||||
|
function! s:is_math() " {{{1
|
||||||
|
return match(map(synstack(line('.'), col('.')),
|
||||||
|
\ 'synIDattr(v:val, ''name'')'), '^texMathZone[EX]$') >= 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
|
|
||||||
" vim: fdm=marker sw=2
|
" vim: fdm=marker sw=2
|
||||||
|
Loading…
Reference in New Issue
Block a user