9
8

More than 5 years have passed since last update.

QuickFixを使う

Posted at

vimgrepやmakeなどの結果をQuickFixで表示させることが多いのですが、検索結果を表示するためにいちいちcopenを打つのは面倒です。QuickfixCmdPostに書くと良いらしいです。

.vimrc
autocmd QuickfixCmdPost make,vimgrep copen

あと、Quickfixのウィンドウだけ最後になってしまうことがあり、どうにかならないのかなと思って調べてみた。下の例は、画面が1個でそのバッファがquickfixなら閉じるという結構強引な感じで書いてます。いい方法ありますか?

.vimrc
function s:QuickFix_Exit_OnlyWindow()                                            if winnr('$') == 1 
    if (getbufvar(winbufnr(0), '&buftype')) == 'quickfix'
      quit
    endif
  endif
endfunction
autocmd WinEnter * call s:QuickFix_Exit_OnlyWindow()

ざっとhelpなどを読んだものをまとめると、winnr('$')は現在表示中の画面数です。
Quickfixのhelpを読むとbuftypeに'quickfix'という名前がついていると書いてあったので↑のようにしてみた。ざっと動かした感じでは、大丈夫そうでしたので、これから使い込んでいこうと思います。

9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8