提问人:xiaochen 提问时间:11/6/2023 最后编辑:xiaochen 更新时间:11/7/2023 访问量:47
vim ctags:如果 lua 函数名称后面有一个空格,则找不到标签
vim ctags:tags not found if one space after lua function name
问:
我已经注释掉了我所有的 vimrc 文件,在我的 macOS () 中,它找不到带有以下命令和源代码的标签22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64 arm Darwin
$ cat x.lua
function test ()
end
$ ctags -R x.lua
$ cat tags
!_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 /[email protected]/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.8 //
test x.lua /^function test ()$/;" f
$ vim -t test
# vim reports the error like "E257: cstag: Tag not found"
如果我删除函数名称后面的空格,比如 ,那么它可以工作。test
function test()
我也在我的 EC2 ubuntu 中对此进行了测试,它甚至可以在函数名称后有一个空格。test
这之后不知道怎么调试,我也问过ChatGPT 3.5,但没能解决这个问题。
答:
1赞
romainl
11/7/2023
#1
在解析文件时,创建了一个标签,请注意尾随空格,而不是标签。这可能是因为 Lua 的默认解析器不希望函数名称和左括号之间有可选的空格。ctags
test
test
由于实际标签是 ,因此搜索 with 或 not 有效,因为搜索是文字的。你将不得不...test
test
-t test
:tag test
- 在 Vim 中搜索 , with the space: ,
test
:tag test
- 或搜索正则表达式:
test
:tag /test
在 Vim 中,或者:
- 从 shell 中搜索正则表达式:.
test
$ vim -t /test
看。:help tag-regexp
如果你不能从你的代码中删除多余的空间,这将是真正的解决方案,在这里,你可以告诉ctags用一点正则表达式搜索新标签(见 )或尝试通用Ctags,如评论中提到的,在这种特定情况下,它可能比也可能不比Exuberant Ctags更聪明。$ man ctags
评论
0赞
xiaochen
11/7/2023
凉!搜索“/test”对我有用。最后,我在我的macOS中使用来解决这个问题,ty!universal ctags
评论