Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM count / determine number of errors in quickfix

Tags:

vim

This may sound silly, but I did not find it in the help.

How to determine the number of errors in the QuickFix, after running :make ?

Or at least see if there are any errors, i.e. errors > 0?

like image 677
Ayman Avatar asked Oct 12 '09 05:10

Ayman


3 Answers

If you want to determine how many errors there are in the quickfix and not just how many entries there are, then you need to filter getqflist:

" 'errorformat' matched %t as an error.
let error_count = len(filter(getqflist(), { k,v -> v.type == 'E' }))

" Anything with a destination file.
let jumpable_count = len(filter(getqflist(), { k,v -> v.bufnr != 0 }))

So if your quickfix looks like:

test.py|387|  import io, os datetime
||                   ^
|| SyntaxError: invalid syntax

Then error_count == 0 and jumpable_count == 1.

like image 94
idbrii Avatar answered Oct 19 '22 20:10

idbrii


You can programmatically get the list of errors with 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

If you just want the total number, use len(getqflist()). eg:

:echo len(getqflist())

If you just want to know interactively, :cw will open the list in a window if there are any errors (and close it if it's already open and there are no errors). The number of lines in that buffer is the number of errors.

like image 29
Laurence Gonsalves Avatar answered Oct 19 '22 20:10

Laurence Gonsalves


You can just use the getqflist() function (see :help getqflist()):

:echo printf("Have %d errors", len(getqflist()))
like image 37
too much php Avatar answered Oct 19 '22 19:10

too much php