我想下面的代碼在列表過濾多個項目:不能夠過濾從列表中選擇多個項目在vim
function! Myfilter (...)
let alltext = getline(1,'$')
for s in a:000
let alltext = filter(alltext, s)
endfor
echo alltext
endfunction
我叫它爲:
:call Myfilter("word1", "word2")
然而,是一個錯誤,因爲s中的值被視爲一個變量而不是字符串。錯誤是:
Error detected while processing function Myfilter:
line 3:
E121: Undefined variable: word1
E121: Undefined variable: word2
而整個alltext打印沒有任何過濾。以下修改也不起作用:
filter(alltext, ' ' . s . ' ')
filter(mylist, 'v:val == s')
filter(alltext, 'match(v:val, s)')
問題在哪裏,我該如何解決它?
什麼是你想實現什麼?從列表中刪除單詞?爲什麼不使用正則表達式? – mike
這個函數的問題在哪裏?爲什麼它不起作用? – rnso
此問題與[this one]相同(是http://stackoverflow.com/questions/43570728/function-to-search-recursively-for-patterns-in-vim),不是嗎? 你只需要一個單詞列表或正則表達式列表? – mike