programmazione è possibile ottenere l'elenco degli errori con 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
Se si desidera solo il numero totale, utilizzare len(getqflist())
. ad esempio:
:echo len(getqflist())
Se si desidera solo conoscere in modo interattivo, :cw
si aprirà l'elenco in una finestra, se ci sono errori (e chiuderlo se è già aperto e non ci sono errori). Il numero di righe in quel buffer è il numero di errori.
fonte
2009-10-12 06:24:30
Se la finestra quickfix contiene il testo non riconosciuto come un errore, la lista restituita da 'getqflist()' conterrà voci per ciascuno di questi Linee. Quindi potresti ancora avere zero errori con 'len (getqflist())' che restituisce un valore diverso da zero. È necessario controllare il flag "valido" all'interno dell'elenco risultante. Usa la funzione 'filter()' per quello. – Ben
'len (filter (getqflist(), 'v: val.valid'))' ti darà il numero di voci rapide valide. In molti casi sarà uguale al numero di voci, ma non sempre. Cercare ': help filter()' sarebbe stato un buon inizio per capirlo. ;-) – Ben
Grazie per aver risposto. Ho appena eseguito alcuni tutorial e scritto una versione normale senza usare 'filter()', vedi [mio gist] (https://gist.github.com/ih4cku/fa5d57f9f1dc5c03b6c36155bf3e2904) se sei interessante. Ovviamente, usare 'filter()' è più elegante. @ Ben – nn0p