I do use Ag as my grep replacement. My problem is that when I search for something that does not exist (search result empty) my quick fix windows closes automatically.

Is that normal? Would it be possible to keep it open with something like "No results found" ?

This is my config

" bind \ (backward slash) to grep shortcut
" https://robots.thoughtbot.com/faster-grepping-in-vim
" https://vi.stackexchange.com/questions/14923/my-ag-shortcut-chokes-on-spaces
function! Ag(args) abort
  execute "silent! grep!" shellescape(a:args)
command! -nargs=+ -complete=file Ag call Ag(<q-args>)
nnoremap \ :Ag<SPACE>

Thank you for your help

1 Answer 1


This is because you are using :cwindow to open the window.

See :help :cwindow:

Open the quickfix window when there are recognized errors. If the window is already open and there are no recognized errors, close the window.

(Emphasis mine.)

Change this to :copen to always open the quickfix window.

If you want the window to display "No results found" instead of just being empty, you will also need an autocommand:

augroup AgQuickfix
  autocmd BufReadPost quickfix setlocal modifiable
        \ | if line('$') == 1 && empty(getline(1))
        \ |   call setline(1, "No results found") 
        \ | endif
        \ | setlocal nomodifiable
augroup END

This is described in :help quickfix.txt (search for BufReadPost).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.