diff --git a/after/syntax/tex.vim b/after/syntax/tex.vim index 1f04cb2..ffb59b7 100644 --- a/after/syntax/tex.vim +++ b/after/syntax/tex.vim @@ -39,7 +39,8 @@ for [style, group, commands] in [ endfor " }}}1 -" {{{1 Add syntax highlighting for \url and \href +" {{{1 Add syntax highlighting for \url, \href, \hyperref + syntax match texStatement '\\url\ze[^\ta-zA-Z]' nextgroup=texUrlVerb syntax match texStatement '\\url\ze\s*{' nextgroup=texUrl syntax match texStatement '\\href' nextgroup=texHref @@ -53,10 +54,14 @@ syntax region texHref matchgroup=Delimiter start='{' end='}' contained syntax region texHrefLinkText matchgroup=Delimiter start='{' end='}' contained \ contains=@Spell +syntax match texStatement '\\hyperref' nextgroup=texHyperref +syntax region texHyperref matchgroup=Delimiter start='\[' end='\]' contained + highlight link texUrl Function highlight link texUrlVerb texUrl highlight link texHref texUrl highlight link texHrefLinkText texSectionZone +highlight link texHyperref texRefZone " }}}1 " {{{1 Improve support for cite commands diff --git a/autoload/vimtex/complete.vim b/autoload/vimtex/complete.vim index e74ef07..00461b8 100644 --- a/autoload/vimtex/complete.vim +++ b/autoload/vimtex/complete.vim @@ -37,22 +37,25 @@ endfunction function! vimtex#complete#omnifunc(findstart, base) " {{{1 if a:findstart - let pos = col('.') - 1 - let line = getline('.')[:pos-1] + let l:pos = col('.') - 1 + let l:line = getline('.')[:l:pos-1] for l:completer in s:completers if !get(l:completer, 'enabled', 0) | return -3 | endif - if line =~# l:completer.pattern . '$' - let s:completer = l:completer - while pos > 0 - if line[pos - 1] =~# '{\|,' || line[pos-2:pos-1] ==# ', ' - return pos - else - let pos -= 1 - endif - endwhile - return -2 - endif + for l:pattern in l:completer.patterns + if l:line =~# l:pattern + let s:completer = l:completer + while l:pos > 0 + if l:line[l:pos - 1] =~# '{\|,\|\[' + \ || l:line[l:pos-2:l:pos-1] ==# ', ' + return l:pos + else + let l:pos -= 1 + endif + endwhile + return -2 + endif + endfor endfor return -3 else @@ -68,7 +71,7 @@ endfunction " {{{1 Bibtex let s:bib = { - \ 'pattern' : '\v\\\a*cite\a*%(\s*\[[^]]*\]){0,2}\s*\{[^}]*', + \ 'patterns' : ['\v\\\a*cite\a*%(\s*\[[^]]*\]){0,2}\s*\{[^}]*$'], \ 'enabled' : 1, \ 'bibs' : '''\v%(%(\\@ \ '\v\\%(' \ . '\a*cite\a*%(\s*\[[^]]*\]){0,2}\s*\{[^}]*' \ . '|\a*ref%(\s*\{[^}]*|range\s*\{[^,}]*%(}\{)?)' + \ . '|hyperref\s*\[[^]]*' \ . '|includegraphics\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*' \ . '|%(include%(only)?|input)\s*\{[^}]*' \ . ')' diff --git a/test/feature/syntax/test-syntax.tex b/test/feature/syntax/test-syntax.tex index d48537b..19ed94a 100644 --- a/test/feature/syntax/test-syntax.tex +++ b/test/feature/syntax/test-syntax.tex @@ -19,8 +19,8 @@ testing \end{quote} \begin{dot2tex} - graph graphname { - a -- b; + graph graphname { + a -- b; b -- c; b -- d; d -- a; @@ -81,6 +81,7 @@ const double pi = 3.1415926535 \url+http://www.google.com+ \href{http://example.com}{Title text} \urldef{\mysite}\url{http://example.com} +\hyperref[asdasd]{asd} \end{document}