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...
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With