在Vim中调整/对齐错误格式输出



我使用Vim/gVim在javascript (node)中编程。我在我的文件类型插件中将jslint连接为makeprg。errorformat:

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

下面是快速修复窗口的输出:

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。是否有可能有条件地填充输出?

合理的数字当然会很好,但我认为这将需要一个源代码补丁到Vim。

快速修复窗口中的信息来自Vim的内部数据结构(格式参见:help getqflist()), Vim决定如何将其可视化。

: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

最新更新