我使用Vim / gVim在javascript(节点)中编程。我在我的filetype插件中将jslint连接为makeprg。这是错误格式:
efm=%-P%f,
\%A%>%\\s%\\?#%*\\d\ %m,%Z%.%#Line\ %l\\,\ Pos\ %c,
\%-G%f\ is\ OK.,%-Q
这是jslint的输出:
routes/pcr.js
#1 'db' was used before it was defined.
db.collection('pcrs', function (err, collection) { // Line 11, Pos 5
#2 'db' was used before it was defined.
db.collection('pcrs', function (err, collection) { // Line 23, Pos 5
#3 'BSON' was used before it was defined.
collection.findOne({'_id': new BSON.ObjectID(id)}, function (err, item) { // Line 24, Pos 40
以下是quickfix窗口的输出:
routes/pcr.js|11 col 5| 'db' was used before it was defined.
routes/pcr.js|23 col 5| 'db' was used before it was defined.
routes/pcr.js|24 col 40| 'BSON' was used before it was defined.
在列号之后,我想留下来说出2位数字(我希望文件不超过99个错误!)所以它看起来像:
routes/pcr.js|11 col 5| 'db' was used before it was defined.
routes/pcr.js|23 col 5| 'db' was used before it was defined.
routes/pcr.js|24 col 40| 'BSON' was used before it was defined.
我想这也会影响0-9行。是否可以有条件地填充输出?
答案 0 :(得分:2)
合理的数字肯定会很好,但我认为这需要Vim的源代码补丁。
quickfix窗口中的信息来自Vim的内部数据结构(格式见:help getqflist()
),Vim决定如何将其可视化。
答案 1 :(得分:1)
:help quickfix-window
提及重新格式化错误列表。
以下设置适用于我(更新):
au BufRead quickfix setl modifiable
\| silent exe "%!perl -ple '
\my ($file, $pos, $msg) = split qr{[|]}, $_, 3;
\my $aligned_pos = sub {
\ my @p = split qr{[ ]}, shift;
\ return if @p == 0;
\ return sprintf q{\\%3s}, @p if @p == 1;
\ return sprintf q{\\%3s \\%s}, @p if @p == 2;
\ return sprintf q{\\%3s \\%s \\%2s}, @p if @p == 3;
\ return sprintf q{\\%3s \\%s \\%2s \\%-8s}, @p if @p == 4;
\ return join q{ }, @p;
\}->($pos);
\$_ = join q{|}, $file, $aligned_pos, $msg;
\'"
\| setl nomodifiable