如何在离开文件时自动关闭快速修复窗口?

发布于 2024-12-05 22:28:29 字数 276 浏览 0 评论 0原文

我使用 vim 中的插件来编译 Tex 文件。当编译出现错误时,它们都会显示在屏幕底部的快速修复窗口中。

当我想离开正在处理的文件(:q:wq 等)时,快速修复窗口可能会很烦人,因为它在我离开缓冲区后保持打开状态我正在处理的文件,迫使我也在快速修复窗口上输入 :q

当我使用 :q 时,有没有办法告诉 vim 立即执行 :close ?我尝试了几种自动命令,但没有效果。

I use a plugin in vim to compile Tex files. When there are errors on compilation, they are all displayed in a quick fix window at the bottom of the screen.

When I want to leave a file I'm working on (:q, :wq, etc) the quickfix window can be annoying because it stays open after I left the buffer of the file I was working on, forcing me to :q on the quick fix window too.

Is there a way to tell vim to immediately execute :close when I use :q? I've tried several autocmds, but to no avail.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

两相知 2024-12-12 22:28:29

添加到您的 .vimrc 文件

aug QFClose
  au!
  au WinEnter * if winnr('

警告:如果快速修复窗口是唯一可见的窗口(也是唯一的选项卡),这将关闭 vim。

) == 1 && &buftype == "quickfix"|q|endif aug END

警告:如果快速修复窗口是唯一可见的窗口(也是唯一的选项卡),这将关闭 vim。

Add to your .vimrc file

aug QFClose
  au!
  au WinEnter * if winnr('

Warning: this will close vim if the quickfix window is the only window visible (and only tab).

) == 1 && &buftype == "quickfix"|q|endif aug END

Warning: this will close vim if the quickfix window is the only window visible (and only tab).

泼猴你往哪里跑 2024-12-12 22:28:29

命令 :qa 将退出所有打开的窗口。

The command :qa will quit all open windows.

十二 2024-12-12 22:28:29

要在离开文件(:q:wq 等)时自动正确关闭多个快速修复/位置/帮助窗口,请将以下代码添加到您的 .vimrc 中:

" s:NextNormalWindow() {{{2
function! s:NextNormalWindow() abort
    for i in range(1, winnr('

这不会在快速修复窗口中打开新选项卡时遇到问题。

)) let buf = winbufnr(i) " skip unlisted buffers if !buflisted(buf) continue endif " skip temporary buffers with buftype set if getbufvar(buf, '&buftype') != '' continue endif " skip the preview window if getwinvar(i, '&previewwindow') continue endif " skip current window if i == winnr() continue endif return i endfor return -1 endfunction " s:QuitIfOnlyWindow() {{{2 function! s:QuitIfOnlyWindow() abort let l:buftype = getbufvar(winbufnr(winnr()), "&buftype") if l:buftype != "quickfix" && l:buftype != "help" return endif " Check if there is more than one window if s:NextNormalWindow() == -1 " Check if there is more than one tab page if tabpagenr('

这不会在快速修复窗口中打开新选项卡时遇到问题。

) == 1 " Before quitting Vim, delete the special buffer so that " the '0 mark is correctly set to the previous buffer. " Also disable autocmd on this command to avoid unnecessary " autocmd nesting. if winnr('

这不会在快速修复窗口中打开新选项卡时遇到问题。

) == 1 if has('autocmd') noautocmd bdelete endif endif quit else " Note: workaround for the fact that in new tab the buftype is set " too late (and sticks during this WinEntry autocmd to the old - " potentially quickfix/help buftype - that would automatically " close the new tab and open the buffer in copen window instead " New tabpage has previous window set to 0 if tabpagewinnr(tabpagenr(), '#') != 0 let l:last_window = 0 if winnr('

这不会在快速修复窗口中打开新选项卡时遇到问题。

) == 1 let l:last_window = 1 endif close if l:last_window == 1 " Note: workaround for the same bug, but w.r.t. Airline " plugin (it needs to refresh buftype and status line after " last special window autocmd close on a tab page if exists(':AirlineRefresh') execute "AirlineRefresh" endif endif endif endif endif endfunction " autoclose last open location/quickfix/help windows on a tab if has('autocmd') aug AutoCloseAllQF au! autocmd WinEnter * nested call s:QuitIfOnlyWindow() aug END endif

这不会在快速修复窗口中打开新选项卡时遇到问题。

To properly close even multiple quickfix/location/help windows automatically when leaving file (:q, :wq, etc.) add following code to your .vimrc:

" s:NextNormalWindow() {{{2
function! s:NextNormalWindow() abort
    for i in range(1, winnr('

This does not have problems with new tab opening from within quickfix window.

)) let buf = winbufnr(i) " skip unlisted buffers if !buflisted(buf) continue endif " skip temporary buffers with buftype set if getbufvar(buf, '&buftype') != '' continue endif " skip the preview window if getwinvar(i, '&previewwindow') continue endif " skip current window if i == winnr() continue endif return i endfor return -1 endfunction " s:QuitIfOnlyWindow() {{{2 function! s:QuitIfOnlyWindow() abort let l:buftype = getbufvar(winbufnr(winnr()), "&buftype") if l:buftype != "quickfix" && l:buftype != "help" return endif " Check if there is more than one window if s:NextNormalWindow() == -1 " Check if there is more than one tab page if tabpagenr('

This does not have problems with new tab opening from within quickfix window.

) == 1 " Before quitting Vim, delete the special buffer so that " the '0 mark is correctly set to the previous buffer. " Also disable autocmd on this command to avoid unnecessary " autocmd nesting. if winnr('

This does not have problems with new tab opening from within quickfix window.

) == 1 if has('autocmd') noautocmd bdelete endif endif quit else " Note: workaround for the fact that in new tab the buftype is set " too late (and sticks during this WinEntry autocmd to the old - " potentially quickfix/help buftype - that would automatically " close the new tab and open the buffer in copen window instead " New tabpage has previous window set to 0 if tabpagewinnr(tabpagenr(), '#') != 0 let l:last_window = 0 if winnr('

This does not have problems with new tab opening from within quickfix window.

) == 1 let l:last_window = 1 endif close if l:last_window == 1 " Note: workaround for the same bug, but w.r.t. Airline " plugin (it needs to refresh buftype and status line after " last special window autocmd close on a tab page if exists(':AirlineRefresh') execute "AirlineRefresh" endif endif endif endif endif endfunction " autoclose last open location/quickfix/help windows on a tab if has('autocmd') aug AutoCloseAllQF au! autocmd WinEnter * nested call s:QuitIfOnlyWindow() aug END endif

This does not have problems with new tab opening from within quickfix window.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文