沒有與這樣的字符串值一個vim變量:Vim腳本:擴展通配符在字符串
foo%:p:r:sbar
%:P:R:S是一個VIM通配符。
如何擴展字符串變量中的所有通配符?
不幸的是expand(my_variable)沒有幫助。 我是否需要指定任何附加參數或使用其他vim函數?
謝謝。
沒有與這樣的字符串值一個vim變量:Vim腳本:擴展通配符在字符串
foo%:p:r:sbar
%:P:R:S是一個VIM通配符。
如何擴展字符串變量中的所有通配符?
不幸的是expand(my_variable)沒有幫助。 我是否需要指定任何附加參數或使用其他vim函數?
謝謝。
嘗試:help expand()
的文檔的這一部分顯得尤爲貼近您:
Modifiers:
:p expand to full path
:h head (last path component removed)
:t tail (last path component only)
:r root (one extension removed)
:e extension only
Example: >
:let &tags = expand("%:p:h") . "/tags"
Note that when expanding a string that starts with '%', '#' or
'<', any following text is ignored. This does NOT work: >
:let doesntwork = expand("%:h.bak")
Use this: >
:let doeswork = expand("%:h") . ".bak"
它看起來像你的拖尾(並可能導致)字符串將不會與expand()
工作。
這並不工作,但:
:echo "foo" . expand("%:p:r:s") . "bar"
也許你可以返工您的腳本,使它們與其他字符串合併之前通配符會擴展。或者,您可以嘗試拆分連接的字符串,展開通配符,然後重新連接。
join(map(split(mystring, '\ze[<%#]'), 'expand(v:val)'), '')
?
我想我自己。 在這種情況下,我將不得不重構很多代碼,因爲字符串是由其他vim函數動態生成的。 有沒有辦法做到這一點? – 2009-11-22 20:47:19