diff --git a/autoload/vimtex/index.vim b/autoload/vimtex/index.vim index 88a9bc0..6d40cd3 100644 --- a/autoload/vimtex/index.vim +++ b/autoload/vimtex/index.vim @@ -170,7 +170,9 @@ function! s:actions_activate(close) dict "{{{1 execute 'keepalt' cmd bnr " Go to entry line - call setpos('.', [0, entry.line, 0, 0]) + if has_key(entry, 'line') + call setpos('.', [0, entry.line, 0, 0]) + endif " Ensure folds are opened normal! zv diff --git a/autoload/vimtex/toc.vim b/autoload/vimtex/toc.vim index 559ea90..91b0a68 100644 --- a/autoload/vimtex/toc.vim +++ b/autoload/vimtex/toc.vim @@ -151,6 +151,24 @@ function! vimtex#toc#get_entries() " {{{1 endif endif + " Convenience includes + let l:fname = matchstr(l:line, s:re_vimtex_include) + if !empty(l:fname) + if l:fname[0] !=# '/' + let l:fname = b:vimtex.root . '/' . l:fname + endif + call add(l:toc, { + \ 'title' : 'Vimtex include: ' + \ . (strlen(l:fname) < 54 + \ ? l:fname + \ : l:fname[0:20] . '...' . l:fname[-30:]), + \ 'number' : '', + \ 'file' : l:fname, + \ 'level' : s:number.current_level, + \ }) + continue + endif + " Bibliography files if l:line =~# s:re_bibs call add(l:toc, s:parse_bib_input(l:line)) @@ -488,6 +506,7 @@ let s:re_sec = '\v^\s*\\%(part|chapter|%(sub)*section)\*?\s*%(\[.{-}\])?\{' let s:re_sec_starred = '\v^\s*\\%(part|chapter|%(sub)*section)\*' let s:re_sec_level = '\v^\s*\\\zs%(part|chapter|%(sub)*section)' let s:re_sec_title = s:re_sec . '\zs.{-}\ze\}?\%?\s*$' +let s:re_vimtex_include = '%\s*vimtex-include:\?\s\+\zs\f\+' let s:re_matters = '\v^\s*\\%(front|main|back)matter>' let s:re_structure = '\v^\s*\\((front|main|back)matter|appendix)>' let s:re_structure_match = '\v((front|main|back)matter|appendix)' diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 8582794..3ce7c8e 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -1710,6 +1710,16 @@ Table of contents~ The ToC entries may be activated/jumped to with or . The local keybindings are described if |g:vimtex_index_show_help| is enabled. +One may force entries into the ToC through designated comments with the +following syntax: > + + % vimtex-include: /path/to/file + +The path may be absolute or relative. In the latter case, it will be relative +to the current root (as printed by |:VimtexInfo|). This will add an entry in +the ToC which makes it easy to open any file. Note, though, that the ToC and +vimtex key mappings may not be available in the target file. + Associated settings: |g:vimtex_toc_enabled| |g:vimtex_toc_fold|