3

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>
endif

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 May 4 '15 at 10:49
  • I have it in both. However, adding an extra CR works – Giuseppe Pes May 4 '15 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. – Martin Tournoij May 4 '15 at 11:07
  • 1
    See also the ag.vim plugin for a much nicer interface. – lcd047 May 4 '15 at 12:15
3

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, privacy policy and cookie policy

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