[英]Vim Quickfix is always opening. Is there a way to get it open only if there are errors?
[英]VIM count / determine number of errors in quickfix
这可能听起来很傻,但我没有在帮助中找到它。
运行:make
后如何确定 QuickFix 中的错误数量?
或者至少看看是否有任何错误,即错误 > 0?
您可以使用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
将在出现任何错误的情况下在窗口中打开列表(如果它已经打开并且没有错误,则关闭它)。 该缓冲区中的行数就是错误数。
您可以只使用getqflist()
函数(请参阅:help getqflist()
):
:echo printf("Have %d errors", len(getqflist()))
如果您想确定 quickfix 中有多少错误,而不仅仅是有多少条目,那么您需要过滤 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 }))
所以如果你的 quickfix 看起来像:
test.py|387| import io, os datetime
|| ^
|| SyntaxError: invalid syntax
然后 error_count == 0 和 jumpable_count == 1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.