2011-09-19 5 views
6

vimでプラグインを使ってTexファイルをコンパイルします。コンパイル時にエラーが発生すると、それらはすべて画面下のクイックフィックスウィンドウに表示されます。ファイルを終了するときにクイックフィックスウィンドウを自動的に閉じる方法は?

私は(:q:wq、など)に取り組んでいるファイルを残したい、私は:qに私を強制的に、私が働いていたファイルのバッファを去った後、それが開いたままになりますので、のQuickFixウィンドウがいらいらすることができますクイックフィックスウィンドウでも。

:qを使用すると、すぐにvimに:closeを実行するように指示する方法はありますか?私はいくつかのautocmdsを試しましたが、無駄です。

+0

':ccl'は役に立ちますか? –

+0

'':ccl''は '':cclose''とまったく同じです... – romeovs

+0

スーパーユーザーの所属 –

答えて

14

はあなた.vimrcファイル

aug QFClose 
    au! 
    au WinEnter * if winnr('$') == 1 && getbufvar(winbufnr(winnr()), "&buftype") == "quickfix"|q|endif 
aug END 

警告に追加します。

+0

これはまさに私が必要としていたものです。ありがとうございます<3 – romeovs

+0

あなたは私の一日を作った – ospider

3

コマンド:qaは、開いているすべてのウィンドウを終了します。 QuickFixウィンドウはウィンドウのみ見える(とのみタブ)であれば、これはVimを閉じます:

1

(など、:wq:q)ファイルを残したときに自動的にも、複数のクイックフィックス/場所/ヘルプウィンドウ適切に閉じるために、あなたの.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 

これは新しいタブに問題を持っていませんクイックフィックスウィンドウ内から開きます。

関連する問題