2011-10-26 58 views
1

單詞的列表,我有一個commnad「COM」女巫產生在標準輸出上的單詞列表如何突出在vim

w1 
w2 
w3 
... 

我需要一個vim的功能,可以執行我的命令,閱讀列表,並突出顯示所有話。

回答

2

這是爲我工作的一個例子:

for word in split(system("cat words.txt"), "\n") 
    call matchadd("Search", word) 
endfor 

這可以被包裹在一個函數(替換爲程序調用與com):

fun MakeMatches() 
    for word in split(system("com"), "\n") 
     call matchadd("Search", word) 
    endfor 
endfun 
2

我會建議使用單請致電matchadd而不是添加多個匹配,因爲它們應該較慢,並且在第二次調用函數時還要注意情況:

function DelMatches() 
    if exists('s:matchnr') 
     try 
      call matchdelete(s:matchnr) 
     catch /\V\^Vim(call):E803:/ 
      " Ignore `ID not found' error 
     endtry 
     unlet s:matchnr 
    endif 
endfunction 
function MakeMatches() 
    call DelMatches() 
    let s:matchnr=matchadd("Search", '\V\<\%('.join(map(split(system("com"), "\n"), 'escape(v:val, "\\")'), '\|').'\)\>') 
endfunction