これは愚かなことかもしれませんが、ヘルプで見つけられませんでした。VIMカウント/クイックフィックスのエラー数を確認する
:make
を実行した後、QuickFixのエラー数を特定するにはどうすればよいですか?
少なくとも、エラーがあるかどうか、つまりエラー> 0かどうかを確認します。
これは愚かなことかもしれませんが、ヘルプで見つけられませんでした。VIMカウント/クイックフィックスのエラー数を確認する
:make
を実行した後、QuickFixのエラー数を特定するにはどうすればよいですか?
少なくとも、エラーがあるかどうか、つまりエラー> 0かどうかを確認します。
あなたがプログラム的getqflist()
とエラーのリストを取得することができます:あなただけの合計数をしたい場合は、len(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
。例えば:
:echo len(getqflist())
あなただけの対話的に知りたい場合は、:cw
はエラーがないかどうかをウィンドウのリストを開く(そしてそれは、すでに開いているとエラーがない場合は、それをクローズ)します。そのバッファ内の行数はエラーの数です。
あなただけgetqflist()
機能を使用することができます(:help getqflist()
を参照してください):
:echo printf("Have %d errors", len(getqflist()))
をクイックフィックスウインドウがテキストはエラーとして認識されていないが含まれている場合、getqflist 'によって返されたリストを()'これらのそれぞれのエントリが含まれていますライン。だから、 'len(getqflist())'がゼロ以外の値を返しても、実際にはゼロエラーが発生する可能性があります。結果リスト内の '有効'フラグをチェックする必要があります。それには 'filter()'関数を使います。 – Ben
'len(filter(getqflist()、 'v:val.valid'))'は有効なquickfixエントリの数を返します。多くの場合、エントリの数と同じになりますが、必ずしもそうではありません。 ':help filter()'を探すことは、それを理解するのに良いスタートとなりました。 ;-) – Ben
お返事ありがとうございます。面白いのであれば、 'filter()'を使わずにいくつかのチュートリアルを赤でレギュラーバージョンを書くだけです。[my gist](https://gist.github.com/ih4cku/fa5d57f9f1dc5c03b6c36155bf3e2904)を見てください。明らかに、 'filter()'を使う方がよりエレガントです。 @Ben – nn0p