0

Is there anyway that I can see the number of result with :Ag

(attached) If somewhere I could see the number of return would be awesome. I can't find any reference for it on Internet. Thanks

My .vimrc setup: https://gist.github.com/houmanka/9790614407bcbed4e12d199b9bef32e8

enter image description here

After I do the search, in the quickfix window I type :set errorformat and I get this:

errorformat=%*[^"]"%f"%*\D%l: %m,"%f"%*\D%l: %m,%-G%f:%l: (Each undeclared identifier is reported only once,%-G%f:%l: for each f
unction it appears in.),%-GIn file included from %f:%l:%c:,%-GIn file included from %f:%l:%c\,,%-GIn file included from %f:%l:%c,%
-GIn file included from %f:%l,%-G%*[ ]from %f:%l:%c,%-G%*[ ]from %f:%l:,%-G%*[ ]from %f:%l\,,%-G%*[ ]from %f:%l,%f:%l:%c:%m,%f(%l)
:%m,%f:%l:%m,"%f"\, line %l%*\D%c%*[^ ] %m,%D%*\a[%*\d]: Entering directory %*[`']%f',%X%*\a[%*\d]: Leaving directory %*[`']%f',%D
%*\a: Entering directory %*[`']%f',%X%*\a: Leaving directory %*[`']%f',%DMaking %*\a in %f,%f|%l| %m
4

:Ag inserts its results into a so-called Quickfix window and, as for anything loaded there, an indication of the current result and total results will be displayed on the right side of the status line. See the 1/46 in your screen shot? That means you're currently on the first result out of a total of 46.

If you've already closed the Quickfix window then just by using the Quickfix navigation commands (:cnext, :cc, :cfirst, etc.) you'll see "[current] of [total]" prefixed to the (new) current result in the message area (command line).

Note, though, that all of the navigation commands can move the cursor. If you're still on the current result then :cc will display the position/total and result text without moving the cursor but if you've previously navigated away you can see the total while ensuring the cursor is not moved by using the nice solution @PeterRincker provides below: :echo len(getqflist()).

Non-Vim Note: Your result count will not be accurate because you have all those || lines in your ag output. This is caused by the --noheading flag. There's no reason for that to be there when feeding Quickfix. Remove it and the result count should be correct.

Epilogue: To save someone from reading the wall of comments below let me just sum up what else they cover beyond the previous paragraph: I discovered there is a variable in the ag plugin, g:ag_prg, that can be used to specify the exact ag command used for searches. It so happens that this is where --noheading originated so OP removed that flag and the problem of extra || lines went away. And they lived happily ever after.

  • Can also use :cc to show the current position in the quickfix list. See :h :cc – Peter Rincker Apr 2 '18 at 14:08
  • @PeterRincker Do you have to have previously closed the Quickfix window? As far as I can tell, it's a no-op when the window is still open. – B Layer Apr 2 '18 at 14:19
  • 1
    I never noticed that. You are correct if the Quickfix window is open then :cc does nothing. I typically don't open the window, so I didnt really notice. I guess you could do echo len(getqflist()) – Peter Rincker Apr 2 '18 at 14:22
  • Great, you saved me from having to figure it out myself. Thanks. Please see my updated answer. – B Layer Apr 2 '18 at 20:03
  • @BLayer See the 1/46 in your screen shot indicates that there is 46 lines in the Quickfix window. There are only 23 results. @PeterRincker :echo len(getqflist()) returns the number of lines in the Quick fix window not the number of the results. If you look in the screenshot you will see after each result we have ||. If I can get rid of them, then method that you suggested works. – Mr H Apr 2 '18 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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