Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use ack or ag within vim with Unite.vim?

Tags:

vim

ack

ag

I have found a lot of pages with config examples such as:

let g:unite_source_grep_command = 'ag'
let g:unite_source_grep_default_opts =
  \ '--line-numbers --nocolor --nogroup --hidden --ignore '
let g:unite_source_grep_recursive_opt = ''

or

" Use ag for searching
let g:unite_source_rec_async_command =
  \ 'ag --follow --nocolor --nogroup --hidden -g ""'
let g:ackprg = 'ag --nogroup --column'
nnoremap <space>/ :Unite grep:.<cr>

Unfortunately, I don't really understand what these are doing or why. What I've played around with it some and have gotten parts of what I want working.

Ideally, I'd just like something similar to what Ack.vim does:

  1. I hit some key mapping, let's say /
  2. I put in my search query
  3. That opens a Unite.vim buffer split at the top which asynchronously uses ack or ag to searches for my search query
  4. I can navigate through results and select one or some to open in splits
like image 375
Jeff Avatar asked Nov 21 '22 21:11

Jeff


1 Answers

Perhaps I'm missing the spirit of this question, but if you just need to configure Unite with ag, that's straightforward: in your .vimrc add:

let g:unite_source_grep_command="ag"
let g:unite_source_grep_default_opts="-i --nocolor --nogroup"

In vim, you would invoke a search like so:

:Unite grep:.
pattern: foobar

Note: Unite doesn't comes with pre-defined mappings, so you have to add your own. If Unite is too much functionality for your needs, consider using Ack.vim with ag (Ag.vim is no longer maintained.) Both plugins fulfill your ideal usage patten; but Unite does a whole bunch more.

like image 111
gregory Avatar answered Nov 24 '22 11:11

gregory