我經常想要擦除加載了給定擴展名的所有緩衝區(通常是由補丁生成的.rej文件)。只是在做:bw [!] * .rej會抱怨如果有多個匹配。有沒有人有任何好的提示?目前我要麼重複使用:bw * .rej + tab-complete,或者如果有很多緩衝區,請使用:ls和:bw一組數字的緩衝區。如何獲得:bwipe * .ext擦除匹配vim中的通配符的所有人
1
A
回答
1
在vim中泛化有點困難(除了文件系統上的文件)。因此,最好的方法似乎是將通配符轉換爲正則表達式,然後檢查緩衝區列表中的每個緩衝區以查看它是否匹配。事情是這樣的:
" A command to make invocation easier
command! -complete=buffer -nargs=+ BWipe call BWipe(<f-args>)
function! BWipe(...)
let bufnames = []
" Get a list of all the buffers
for bufnumber in range(0, bufnr('$'))
if buflisted(bufnumber)
call add(bufnames, bufname(bufnumber))
endif
endfor
for argument in a:000
" Escape any backslashes, dots or spaces in the argument
let this_argument = escape(argument, '\ .')
" Turn * into .* for a regular expression match
let this_argument = substitute(this_argument, '\*', '.*', '')
" Iterate through the buffers
for buffername in bufnames
" If they match the provided regex and the buffer still exists
" delete the buffer
if match(buffername, this_argument) != -1 && bufexists(buffername)
exe 'bwipe' buffername
endif
endfor
endfor
endfunction
它可以作爲:
:BWipe *.rej
或:
:BWipe *.c *.h
+0
這非常有幫助,謝謝! – Luke 2010-08-20 16:48:01
0
順便說一句,我結束了一個非常低技術的解決方案去(我個人喜歡儘可能少的修改vim以便我在任何機器上都可以):
我添加了一個映射:
:地圖<比照>:BW *名爲.rej
後來我反覆按 <比照> <標籤> <CR>
+0
聽起來合理。通過在可用的任意版本控制下保留整個'.vim'(或Windows上的vimfiles)和vimrc,我可以繞過「在任何機器的家中」問題。這樣,我所做的任何更改都會被推送到我正在使用的任何一臺機器(或USB存儲棒)。 – DrAl 2011-01-11 18:00:48
相關問題
- 1. 如何從word文檔中獲得匹配通配符的所有字符串
- 2. 模式匹配中的Scala擦除
- 3. 匹配除匹配(多字)模式以外的所有字符
- 4. 如何在VIM中獲得更好的支架匹配/對齊?
- 5. 獅身人面像通配符匹配
- 6. 使用XPath函數擦除所有匹配內容
- 7. 如何列出easymotion vim中的所有匹配
- 8. 如何在正則表達式中獲得通配符的匹配部分?
- 9. 如何獲取字符串中所有匹配的位置?
- 10. 刪除所有匹配類中的jQuery
- 11. 如何獲得所有匹配regex1的字符串後跟一個字符串?
- 12. 如何獲得字符串中正則表達式的所有匹配?
- 13. awk,第4列所有匹配通配符之前的@
- 14. 如何在Vim中刪除所有匹配模式和行的行?
- 15. 除匹配值外,我如何匹配所有內容?
- 16. 如何獲得所有可能的匹配std :: regex
- 17. 如何獲得與MongoDB $ elemMatch的所有匹配?
- 18. 如何獲得通過通配符
- 19. 如何刪除不匹配通配符的文件?
- 20. 刪除所有匹配鍵
- 21. 如何獲得僅匹配字符的第一個字符匹配結果
- 22. Vim語法高亮文件:如何匹配所有出現的字符/符號?
- 23. 如何匹配除逗號以外的所有特殊字符
- 24. PHP如何找到字符串後匹配/通配符/匹配
- 25. .NET路由匹配所有模式(通配符),但有例外
- 26. 如何匹配R中的所有匹配項?
- 27. 如何匹配Regex中特定模式的所有匹配項?
- 28. 如何匹配排除特定字符的序列中的所有字符?
- 29. 正則表達式:如何匹配字符串中@something的所有匹配項
- 30. 還有就是得分的通配符匹配和精確匹配之間的不匹配
聽起來像是你可能需要編寫(或發現)一個插件來做到這一點。 :bwipe只會像你所經歷的那樣需要一個'bufname'。 – cam 2010-08-17 21:59:19