Here is a revised version of the feature published by Prince Gulash. This version takes a list of words as input and returns a formatted and alphabetical string of result:
function! IndexByWord( wordlist ) let temp_dict = {} for word in a:wordlist redir => result sil! exe ':g/' . word . '/#' redir END let tmp_list = split(strtrans(result),"\\^\@ *") let res_list = [] call map(tmp_list, 'add(res_list,str2nr(matchstr(v:val,"^[0-9]*")))') let temp_dict[word] = res_list endfor let result_list = [] for key in sort(keys(temp_dict)) call add(result_list, key . ' : ' . string(temp_dict[key])[1:-2]) endfor return join(result_list, "\n") endfunction
One way to invoke this:
echo IndexByWord(['word1', 'word2', 'word3', etc])
There should not be a problem with a long list of words, although in this case you probably want to use a list variable, and getting the results, of course, takes longer. For example:
let my_word_list = ['word1', 'word2', . . . 'word1000'] echo IndexByWord(my_word_list)
Herbert sitz
source share