Vim: 函数切换到当前QuickFix window 并执行命令

Vim: function to switch to the current QuickFix window and perform a command

我正在尝试为 Vim 编写一个小脚本,它会在 :make 之后快速将光标切换到当前 QuickFix window(如果存在),并执行命令(即,它将光标移动到最后一行)。这样默认可以看到build命令的详细结果

我正在尝试在 QuickFixCmdPost:

中注册我的函数
fu! QfMyFunc()
endfunction

au! QuickFixCmdPost make call QfMyFunc()

但是我找不到应该使用什么功能来找到当​​前的 QuickFix window,以及如何切换到它。我需要这样做,因为似乎即使在处理 QuickFixCmdPost 时,当前光标上下文也设置在用户在使用 :make 之前编辑的缓冲区上。

我可能可以枚举所有缓冲区,但是如果当前缓冲区是 QuickFix window 并且它位于当前选项卡中,我应该如何区分?

编辑:感谢 Ingo Karkat,我已经设法编写了正确的脚本。不漂亮,但很管用!

fu! QfScrollToEnd()
    for i in tabpagebuflist()
        if getbufvar(i, "&buftype") == "quickfix"
            :copen
            let l:lines = line("$") " get last line
            call cursor(l:lines, 1) " move the cursor to last line
            :wincmd p
            break
        endif
    endfor
endfunction

au! QuickFixCmdPost make call QfScrollToEnd()

:help :copen 提供一些提示:

      The window will contain a special buffer, with
      'buftype' equal to "quickfix".  Don't change this!
      The window will have the w:quickfix_title variable set
      which will indicate the command that produced the
      quickfix list.

所以,这是一种方式:

:echo !empty(filter(tabpagebuflist(), 'getbufvar(v:val, "&buftype") ==# "quickfix"'))

一旦您确定有一个可见的 quickfix window,您就可以使用 :copen 来访问它。然后 return 通过 :wincmd p.

到前面的 window