vim: 运行 a shell (not make, not perl, not ...), 解析输出,跳转到错误位置

vim: run a shell (not make, not perl, not ...), parse output, jump to error locations

在不同的编辑器中,我很习惯这个工作流程:

  1. 使用通用组合键 运行 任意 shell 命令(例如,makeperl -cw script.plrake cucumberrubocop -D -R./my_fancy_build_script.sh)
  2. 编辑器 运行 在子进程中执行命令,输出在编辑器 window 中滚动。错误位置 (file:number) 使用大量静态正则表达式进行解析(即,无需预先告诉编辑器输出来自 gccperl或任何其他工具)。
  3. 在编译期间(和之后),输出一直保留到我关闭该缓冲区。
  4. 我可以按另一个组合键跳转到下一个(或上一个)错误位置。
  5. 我可以在该缓冲区中手动导航(像往常一样),当我按 Enter 键时,我会到达那个错误位置。

到目前为止一切顺利。

vimquickfix。它似乎基本上做我想做的事。我没有找到如何执行步骤 1。我确实知道如何使用 :make 来 运行 make,或者如何使用 Perl 插件来 运行 Perl 脚本,或者 :grep 等等;我没有找到 运行 任何旧 shell 命令 而不使用特定语言插件 的通用命令。如果我使用通常的 ! 命令,输出是 a) 按键后消失和 b) quickfix.

不可用

有没有类似我在其他编辑器中使用的东西?在 vi 中我该怎么做?

编辑:我尝试了 :set makeprg='$COMMAND' 然后 :make 但只有当 $COMMAND 不包含空格时才有效。

我不想手动将命令的输出重定向到某个文件,并使用 vim -q file 打开它,如 quickfix 文档中所示。

Vi 没有 "quickfix" 功能。

如果 "Vi" 是指 "Vim",是的,quickfix window 几乎完全适合第 2、3、4、5 点。

  1. The editor runs the command in a subprocess, the output is scrolled in an editor window. Error locations (file:number) are parsed using a large(ish) amount of static regexpes (i.e., it is not necessary to tell the editor up front that the output is from gcc, perl or whatever other tool).

对于编译或 运行 语法检查器,您需要使用 :make 并在每个文件类型的基础上设置 makeprg 选项(也可能 errorformat) :

:set makeprg=foo\ --bar\ -baz
:make

makeprgerrorformat 通常由文件类型的 ftplugin 或通过 :compiler 命令设置。

对于 grepping,你需要使用 :grep 命令,如果你想使用 grep 替代方案,则可能设置 grepprggrepformat 选项:

:grep foo **/*.c

除了 grep、编译器和语法检查器之外,您还可以使用 :cexpr:cfile 命令填充快速修复列表(和 window),这些命令最接近65=]我能想到的quickfix命令:

:cexpr system("foo")
  1. During (and after) the compilation, the output stays until I close that buffer.

是的,这就是 quickfix window 的工作原理。

  1. I can press another key combination to jump to the next (or previous) error location.
:cn
:cp
:cc5

如果需要,您可以创建自定义映射。

  1. I can manually navigate in that buffer (as usual) and when I press Enter, I land on that error location.

是的,这就是你如何使用 quickfix window。

quickfixwindow不会自动打开,但可以使用:cnext:cprevious:cfirst:clast等命令跳转到错误在列表中:

:cn
:cn
:cp

要打开 quickfix window,请使用 :cwindow 命令:

:cwindow

如果您希望在列出 errors/locations 时自动打开 quickfix window,请将这些行添加到您的 vimrc:

augroup autoqf
    autocmd!

    " automatically open the location/quickfix window after :make, :grep,
    " :lvimgrep and friends if there are valid locations/errors
    autocmd QuickFixCmdPost [^l]* cwindow
    autocmd QuickFixCmdPost l*    lwindow
augroup END