The following script provides the :Ambiguous
command. It displays keywords (read :h 'iskeyword'
) that are the same but have different letter case in the location-list
window.
The script is explained through its comments:
function! s:display_ambiguous() abort
let buckets = {}
" Split all text in the buffer by non-keywords.
for word in split(join(getline(1, '$')), '\%(\k\@!.\)\+')
" Words are collected into a bucket, keyed by the lowercased word.
let key = tolower(word)
if !has_key(buckets, key)
let buckets[key] = []
endif
" Only add words that haven't been seen before.
if index(buckets[key], word) == -1
call add(buckets[key], word)
endif
endfor
let ambiguous = []
for [key, items] in items(buckets)
" If a bucket has more than one item, add it to the results.
if len(items) > 1
call add(ambiguous, {
\ 'text': join(items, ', '),
\ 'bufnr': bufnr('%'),
\ })
endif
endfor
if !empty(ambiguous)
" Set the contents of the location-list window.
call setloclist(0, ambiguous, 'r')
" Display the location-list window.
lopen
endif
endfunction
command! Ambiguous call s:display_ambiguous()
data1
orData1
, but you don't want it in a search pattern? What do you want it in then?