开发者

Case insensitive tag searching in Vim

开发者 https://www.devze.com 2023-04-01 02:07 出处:网络
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.

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 sensitiv开发者_运维知识库e 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...


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()


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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号