I am using AG to simplifying and improve the search in my Vim. I remapped K to search for the current selected word as follows:

if executable('ag')
  set grepprg=ag\ --nogroup\ --nocolor
  command -nargs=+ -complete=file -bar Ag silent! grep! <args>|cwindow|redraw!

  nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
  nnoremap ff :Ag<SPACE>

However this doesn't work as expected. When I hit the keyboard K, a small windows opens up in the bottom, showing the following message:

enter image description here

Then, I hit Enter and it goes to the results. How can I avoid this window message and go directly to the result page?

  • Try adding extra <CR> at the end of mapping: nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR><CR> .
    – tivn
    Commented May 4, 2015 at 10:49
  • I have it in both. However, adding an extra CR works Commented May 4, 2015 at 10:55
  • 4
    Mapping the mapping 'silent' also works: nnoremap <silent> K ..., this will prevent you from seeing the shell output from ag. I'm not sure if this is the 'proper' way to fix this, though. Commented May 4, 2015 at 11:07
  • 1
    See also the ag.vim plugin for a much nicer interface.
    – lcd047
    Commented May 4, 2015 at 12:15

1 Answer 1


I use silver searcher too and actually I ended up with this binding:

nnoremap K :silent grep! "\b\s?<C-R><C-W>\b"<CR>:cw<CR>:redr!<CR>

See at :redr! command at the end it cause to redrawing whole screen because sometime after opening results in terminal window, vim doesn't redraw whole screen.

And also there is \s? in regular expression. Without it vim would delete first b letter of the word.

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.