我目前正在尝试使 vim 的 tagbar 插件能够在 Mac OS X 上处理 Latex 文件。
这是我的 ~/.ctags 文件:
--langdef=latex
--langmap=latex:.tex
--regex-latex=/^\\tableofcontents/TABLE OF CONTENTS/s,toc/
--regex-latex=/^\\frontmatter/FRONTMATTER/s,frontmatter/
--regex-latex=/^\\mainmatter/MAINMATTER/s,mainmatter/
--regex-latex=/^\\backmatter/BACKMATTER/s,backmatter/
--regex-latex=/^\\bibliography\{/BIBLIOGRAPHY/s,bibliography/
--regex-latex=/^\\part[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/PART \2/s,part/
--regex-latex=/^\\part[[:space:]]*\*[[:space:]]*\{([^}]+)\}/PART \1/s,part/
--regex-latex=/^\\chapter[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/CHAP \2/s,chapter/
--regex-latex=/^\\chapter[[:space:]]*\*[[:space:]]*\{([^}]+)\}/CHAP \1/s,chapter/
--regex-latex=/^\\section[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/\. \2/s,section/
--regex-latex=/^\\section[[:space:]]*\*[[:space:]]*\{([^}]+)\}/\. \1/s,section/
--regex-latex=/^\\subsection[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/\.\. \2/s,subsection/
--regex-latex=/^\\subsection[[:space:]]*\*[[:space:]]*\{([^}]+)\}/\.\. \1/s,subsection/
--regex-latex=/^\\subsubsection[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/\.\.\. \2/s,subsubsection/
--regex-latex=/^\\subsubsection[[:space:]]*\*[[:space:]]*\{([^}]+)\}/\.\.\. \1/s,subsubsection/
--regex-latex=/^\\includegraphics[[:space:]]*(\[[^]]*\])?[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/\3/g,graphic+listing/
--regex-latex=/^\\lstinputlisting[[:space:]]*(\[[^]]*\])?[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/\3/g,graphic+listing/
--regex-latex=/\\label[[:space:]]*\{([^}]+)\}/\1/l,label/
--regex-latex=/\\ref[[:space:]]*\{([^}]+)\}/\1/r,ref/
--regex-latex=/\\pageref[[:space:]]*\{([^}]+)\}/\1/p,pageref/
这是我的 ~/.vimrc 中的相应部分:
let g:tagbar_type_tex = {
\ 'ctagstype' : 'latex',
\ 'kinds' : [
\ 's:sections',
\ 'g:graphics:0:0',
\ 'l:labels',
\ 'r:refs:1:0',
\ 'p:pagerefs:1:0'
\ ],
\ 'sort' : 0,
\ }
我基本上从这个链接得到了所有这些:https://github.com/vim-scripts/Tagbar/blob/master/doc/tagbar.txt
不幸的是,当我启动标签栏时,没有任何反应,当我执行 :UpdateTags 时,出现以下错误:
easytags.vim 3.7: Exuberant Ctags doesn't support the 'plaintex' file type! (at function xolox#easytags#update..<SNR>20_check_cfile, line 22)
ctags --version 结果为:
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
Compiled: Oct 1 2014, 16:18:15
Addresses: <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c686465696e697e784c797f697e7f227f63797e6f696a637e6b6922626978" rel="noreferrer noopener nofollow">[email protected]</a>>, http://ctags.sourceforge.net
Optional compiled features: +wildcards, +regex
和“which ctags”在:
/usr/local/bin/ctags
当我执行 ctags --verbose Abstract.tex 时,它会找到 ~/.ctags 文件并生成此标记文件:
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2e4a46474b4c4b5c5a6e5b5d4b5c5d005d415b5c4d4b48415c494b00404b5a" rel="noreferrer noopener nofollow">[email protected]</a>/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.8 //
. Abstract abstract.tex /^\\section*{Abstract}$/;" s
文件本身如下所示:
\section*{Abstract}
Let's see what we can do here...
我错过了什么? :(
诚挚的问候并感谢您的帮助:)
最佳答案
EasyTags 问题
EasyTags 使用当前缓冲区的文件类型来确定应传递给
ctags
的参数。文件的
filetype
由 Vim 设置为plaintex
,这是*.tex
文件的默认值。所以......你会得到这个错误,因为plaintex
不被ctags
识别。
标签栏问题
根据 the documentation ,您应该在自定义配置中使用
filetype
:g:tagbar_type_{vim filetype}
由于您的
*.tex
文件被识别为plaintex
,因此您的g:tagbar_type_tex
将永远不会被使用。
自由解决方案
将这些行添加到您的
~/.vimrc
中,以强制 Vim 将*.tex
文件识别为latex
:augroup latex autocmd! autocmd BufRead,BufNewFile *.tex set filetype=latex augroup END
将您的自定义标签栏配置更改为:
g:tagbar_type_tex
至:
g:tagbar_type_latex
仅当 Vim 配置为与 latex
文件类型(ftplugin、语法、缩进...)良好配合时,此解决方案才有效,这充其量是可疑的。 p>
保守解决方案
在
~/.ctags
配置中使用plaintex
而不是latex
:--langdef=plaintex --langmap=plaintex:.tex --regex-plaintex=/^\\tableofcontents/TABLE OF CONTENTS/s,toc/ ...
将您的自定义标签栏配置更改为:
let g:tagbar_type_tex = { \ 'ctagstype' : 'latex', ...
至:
let g:tagbar_type_plaintex = { \ 'ctagstype' : 'plaintex', ...
关于vim - 对 latex 文件使用 vims tagbar 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26145505/