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

1

7

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
Lynnet answered 14/4, 2015 at 21:28 Comment(1)
Have you considered using Ag.vim?Interplay
M
1

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.

Michellemichels answered 27/1, 2017 at 16:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.