2009-10-12 11 views
9

में त्रुटियों की संख्या निर्धारित करें यह मूर्खतापूर्ण लग सकता है, लेकिन मुझे इसे मदद में नहीं मिला।वीआईएम गणना/Quickfix

:make चलाने के बाद, QuickFix में त्रुटियों की संख्या को निर्धारित करने के लिए कैसे करें?

या कम से कम देखें कि क्या कोई त्रुटि है, यानी त्रुटियां> 0?

उत्तर

13

आप प्रोग्राम के रूप में getqflist() साथ त्रुटियों की सूची प्राप्त कर सकते हैं:

getqflist()      *getqflist()* 
     Returns a list with all the current quickfix errors. Each 
     list item is a dictionary with these entries: 
      bufnr number of buffer that has the file name, use 
       bufname() to get the name 
      lnum line number in the buffer (first line is 1) 
      col column number (first column is 1) 
      vcol non-zero: "col" is visual column 
       zero: "col" is byte index 
      nr error number 
      pattern search pattern used to locate the error 
      text description of the error 
      type type of the error, 'E', '1', etc. 
      valid non-zero: recognized error message 

     When there is no error list or it's empty an empty list is 
     returned. Quickfix list entries with non-existing buffer 
     number are returned with "bufnr" set to zero. 

     Useful application: Find pattern matches in multiple files and 
     do something with them: > 
      :vimgrep /theword/jg *.c 
      :for d in getqflist() 
      : echo bufname(d.bufnr) ':' d.lnum '=' d.text 
      :endfor 

तुम सिर्फ कुल संख्या चाहते हैं, len(getqflist()) का उपयोग करें। उदाहरण के लिए:

:echo len(getqflist()) 

तुम सिर्फ सहभागी जानना चाहते हैं, :cw यदि कोई त्रुटि है एक विंडो में सूची खुल जाएगी (और इसे बंद अगर यह पहले से ही खुला है और कोई त्रुटि नहीं है)। उस बफर में लाइनों की संख्या त्रुटियों की संख्या है।

+3

QuickFix खिड़की शामिल पाठ एक त्रुटि के रूप में मान्यता प्राप्त नहीं है, तो सूची 'getqflist द्वारा दिया()' इनमें से प्रत्येक के लिए प्रविष्टियों में शामिल होंगे लाइनों। तो आप वास्तव में 'len (getqflist()) 'शून्य-वापसी लौटने के साथ शून्य त्रुटियों में हो सकते हैं। आपको परिणामी सूची में 'मान्य' ध्वज की जांच करनी होगी। इसके लिए 'फ़िल्टर()' फ़ंक्शन का उपयोग करें। – Ben

+2

'लेन (फ़िल्टर (getqflist(), 'v: val.valid')) 'आपको वैध Quickfix प्रविष्टियों की संख्या देगा। कई मामलों में यह प्रविष्टियों की संख्या के बराबर होगा, लेकिन हमेशा नहीं। खोज रहे हैं ': मदद फ़िल्टर()' इसे समझने के लिए एक अच्छी शुरुआत होगी। ;-) – Ben

+0

जवाब देने के लिए धन्यवाद। मैं बस कुछ ट्यूटोरियल लाल करता हूं और 'फ़िल्टर()' का उपयोग किए बिना एक नियमित संस्करण लिखता हूं, [मेरी जिस्ट] (https://gist.github.com/ih4cku/fa5d57f9f1dc5c03b6c36155bf3e2904) देखें यदि आप दिलचस्प हैं। जाहिर है, 'फ़िल्टर()' का उपयोग करना अधिक सुरुचिपूर्ण है। @Ben – nn0p

1

तुम बस getqflist() समारोह का उपयोग कर सकते (:help getqflist() देखें):

:echo printf("Have %d errors", len(getqflist()))