简体   繁体   English

如何在Vim标签文件中找到违规格式错误

[英]How to find offending format error in Vim tags file

I've recently seen this error whenever I hit autocomplete macros in Vim (eg ctrl-n): 每当我点击Vim中的自动完成宏(例如ctrl-n)时,我最近都会看到这个错误:

E431: Format error in tags file "tags"

The tags file is generated with Exuberant Ctags and it's about 1MB. 标签文件是使用Exuberant Ctags生成的,大约是1MB。 How do I find the error that's triggering this error? 如何找到触发此错误的错误?

我在生成的标签文件中找到了一些额外的行!_TAG_FILE_FORMAT行。当我删除这些额外的行时,vim开始工作。

The tags database is line-oriented; 标签数据库是面向行的; after the header (line(s) starting with !_TAG_FILE_... ), each line corresponds to a tag. 在标题之后(以!_TAG_FILE_...开头的行),每行对应一个标记。

By using binary search , you should be able to quickly locate the offending line(s): Save a copy of the tags file, remove one half, test. 通过使用二进制搜索 ,您应该能够快速找到有问题的行:保存标签文件的副本,删除一半,测试。 If you still get the error, repeat (until you're down to one line). 如果仍然出现错误,请重复(直到您下降到一行)。 Else, take the other half and repeat. 否则,拿另一半重复一遍。

This is a general troubleshooting technique; 这是一般的故障排除技术; for example, it's also helpful to locate problems in Vim plugins (by disabling one half of them). 例如,它也有助于在Vim插件中找到问题(通过禁用它们中的一半)。

Really long function names can cause this error. 实际上很长的函数名称可能会导致此错误。 You can find these functions by opening the tags file in vim and looking for method names longer than 50 chars. 您可以通过在vim中打开标记文件并查找长度超过50个字符的方法名称来找到这些函数。

/^[^\t]{50,}

I think ctags has a problem with parsing java script files. 我认为ctags解析java脚本文件有问题。 Excluding it from tagging fixed this problem for me. 从标记中排除它为我修复了这个问题。

ctags -R --exclude=*.js .

In addition to jaster 's answer: 除了jaster的回答:

I found this, which states that lines longer that 512 characters break vim: 1. Keep the text short, because: - The line length that Vi can handle is limited to 512 characters. 我发现了这一点,它表明1. Keep the text short, because: - The line length that Vi can handle is limited to 512 characters.个字符打破了vim: 1. Keep the text short, because: - The line length that Vi can handle is limited to 512 characters. http://ctags.sourceforge.net/FORMAT http://ctags.sourceforge.net/FORMAT

EDIT: updated source: https://neovim.io/doc/user/vi_diff.html Maximum length of a line in a tags file: 512 bytes. 编辑:更新源: https Maximum length of a line in a tags file: 512 bytes.

I indeed did have a tag line longer that 512 characters - removing that line fixed the issue for me. 我确实有一个超过512个字符的标记行 - 删除该行为我解决了问题。

I solved this problem by rebuilding the tags. 我通过重建标签解决了这个问题。

First remove all tags files and then rebuild tags from your project. 首先删除所有标签文件,然后从项目中重建标签。

I think the reason was i built the tags files twice, first time the tags built for child directories, then build the parent directories. 我认为原因是我构建了两次标签文件,第一次为子目录构建标签,然后构建父目录。

So, the child directories tags couldn't contain some parent directories information. 因此,子目录标记不能包含某些父目录信息。

I came across the same issue, seems not all file formats are well supported. 我遇到了同样的问题,似乎并非所有文件格式都得到很好的支持。 I used the option -L to create tags for only c and c++ files ,the issue went away . 我使用选项-L为c和c ++文件创建标签,问题就消失了。 You might want to try the following , just substitute the *.postfix with the corresponding format you need. 您可能想尝试以下操作,只需将* .postfix替换为您需要的相应格式。

ctags -L $(find . -name *.c -or -name *.cpp -or -name *.h -or -name *.lua )

删除不符合ctags标准的额外行为我解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM