Vim 中不区分大小写的标签搜索

发布于 2024-12-01 17:42:01 字数 421 浏览 1 评论 0原文

在大多数情况下,我发现区分大小写的标签搜索是合适的。我们使用的大多数语言都区分大小写,因此这是可取的。

但是,我的工作场所中有一个 DSL,它使用不区分大小写的标识符。我为这个 DSL 生成标签,甚至可以使用 Foldcase 对其进行排序(并在标签文件中设置适当的标志),但 Vim 似乎仍然对标识符进行区分大小写的匹配。

我希望 Vim 能够将“折叠大小写”标记文件理解为“这种语言不区分大小写”。有这样的设定吗?

我想我可以为这个文件类型打开 ignorecase (我关掉标签文件并更改一些其他设置),但是当大小写不匹配时,Vim 会对我咆哮。我只是想用一种方式对 Vim 说:“嘿,这不区分大小写,所以没关系,你不需要为此对我大喊大叫。”一般来说,我似乎希望 Vim 能够从标签文件的排序方式解释意图,但也许这不是一个广泛持有的愿望......

For the most part, I find case sensitive tag searching to be appropriate. Most of the languages that we use are case sensitive, so this is desirable.

However, I have a DSL in my workplace that uses case insensitive identifiers. I generate tags for this DSL, and I can even sort it with foldcase (and set the appropriate flag in the tag file), but Vim still appears to do case sensitive matching on the identifiers.

What I would love is if Vim could understand a 'folded case' tagfile as "this language is case insensitive." Is there such a setting?

I suppose I could turn on ignorecase for this filetype (I switch out the tags file and change a few other settings anyway), but then Vim barks at me when the case doesn't match. I'd just love a way to say to Vim, "hey, this isn't case sensitive so it's ok, you don't need to yell at me about it." Generally it seems desirable to me that Vim could just interpret the intent from the way the tag file is sorted, but maybe that isn't a broadly held desire...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南…巷孤猫 2024-12-08 17:42:01

最终我只是做了ignorecase解决方案。我的 vimrc 中有这些:

autocmd BufEnter  *                 setlocal noignorecase
autocmd BufEnter  *.{dsl-a,dsl-b*}  setlocal ignorecase

烦人,但问题已解决;我希望 Vim 能够注意到标签文件中的标头:

!_TAG_FILE_SORTED   2   /0=unsorted, 1=sorted, 2=foldcase/

唉,看来它没有。


前几天我遇到了一个问题,它为大众提供了进一步的文档;找不到我要搜索的一些标签,但当我查看标签文件时,它们就在那里。然后我注意到被跳过的项目上方有一些行具有相同的前导字符,但有一个下划线;我意识到下划线在字母之前排序,并想知道这是否可能是一个问题(下划线是大写 Z 和小写 A 之间出现的六个字符之一,但在 C 兼容标识符中是唯一有效的字符)。

为了咯咯地笑,我手动重新排列了有问题的部分,以便在字母后面出现下划线。我什至编写了一个最小的测试用例,并为 bugs@vim 编写了一份大错误报告,然后决定查看标签文档以“引用适当的参考”。它被埋在 :help tagbsearch 的末尾,即对我们这些长期看书的人来说没什么用处。

请注意,大小写必须折叠为大写才能正常工作。

对我的 Python 脚本进行一行更改修复了我的标记文件:

if casefold:
    tags.sort(key=str.upper)  # tag file requires case folding to be folded to upper case
else:
    tags.sort()

Ultimately I just did the ignorecase solution. I have these in my vimrc:

autocmd BufEnter  *                 setlocal noignorecase
autocmd BufEnter  *.{dsl-a,dsl-b*}  setlocal ignorecase

Annoying but problem solved; I'd hoped that Vim would notice the header in the tag file:

!_TAG_FILE_SORTED   2   /0=unsorted, 1=sorted, 2=foldcase/

Alas it appears that it does not.


I ran into an issue the other day which bears further documentation for the masses; some of the tags I'd search for were not found but when I looked in the tags file they were there. Then I noticed that there were lines above the item that was getting skipped that had the same leading characters but then an underscore; I realized that the underscore was sorting before the letters and wondered if that might have been a problem (underscore is one of six characters that appear between captial Z and lower case A but the only one that's valid in a C compatible identifier).

For giggles I manually resorted the offending section so that underscores appeared after the letters. I even worked up a minimal test case and wrote up a big bug report for bugs@vim and then decided to look in the documentation on tags to "cite the appropriate reference". There it was buried toward the end of :help tagbsearch, i.e. of little use to those of us who are chronic tl;dr-ers.

Note that case must be folded to uppercase for this to work.

A one line change to my Python script fixed my tag file:

if casefold:
    tags.sort(key=str.upper)  # tag file requires case folding to be folded to upper case
else:
    tags.sort()
冷情妓 2024-12-08 17:42:01

我对 vim 比较陌生,但我将其添加到我的 .vimrc 中,到目前为止它似乎对我来说效果很好。

"Tag jumping

function! TagInsensitiveJump()
  execute ":tj /\\c" . expand("<cword>") 
endfunction

nnoremap <C-]> :call TagInsensitiveJump()<CR>

I'm relatively new to vim, but I added this to my .vimrc and it seems to work well for me so far.

"Tag jumping

function! TagInsensitiveJump()
  execute ":tj /\\c" . expand("<cword>") 
endfunction

nnoremap <C-]> :call TagInsensitiveJump()<CR>
琴流音 2024-12-08 17:42:01

这不是一个合适的答案,但希望它能成为一个合适的答案!

你能否提供更多细节?比如,一个小的工作示例?

这是我的尝试,但我不确定它是否说明了你在说什么。我还会将其保留在 gist 中,以防您想要合作,也许我们可以找到答案一起。

标签:

blah    a.txt   1

a.txt:

bLah

相同要点

重现步骤:

  1. 运行 vim
  2. do :setignorecase
  3. do :tag blah
  4. 获取消息:“tag 1 of 1 or more using tag with different case!”

另外,看起来最近有人在 Vim 用户邮件列表上问了这个问题,但是我没有看到任何回复。

This isn't a suitable answer, but hopefully it will become one!

Will you provide more details? Like, a small working example?

Here's my attempt at one, but I'm not sure if it illustrates what you're talking about. I'll also keep it in a gist in case you want to collaborate, and maybe then we can find the answer together.

tags:

blah    a.txt   1

a.txt:

bLah

Gist of same.

Steps to reproduce:

  1. run vim
  2. do :set ignorecase
  3. do :tag blah
  4. get message: "tag 1 of 1 or more Using tag with different case!"

Also, looks like someone asked this question recently on the Vim user mailing list, but I don't see any responses.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文