Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Created December 2, 2010 07:19
Show Gist options
  • Select an option

  • Save Sixeight/724926 to your computer and use it in GitHub Desktop.

Select an option

Save Sixeight/724926 to your computer and use it in GitHub Desktop.
unite-grep: grep source for unite.vim
" grep source for unite.vim
"
" setting example:
"
" let g:unite_source_grep_default_dir = '~/.vim'
" let g:unite_source_grep_default_opts = '-iR'
let s:grep_source = { 'name': 'grep', 'is_volatile': 1 }
function! s:grep_source.gather_candidates(args, context)
let l:directory = get(a:args, 0, g:unite_source_grep_default_dir)
let l:extra_opts = get(a:args, 1, g:unite_source_grep_default_opts)
if l:directory =~ '^-'
let l:extra_opts = l:directory
let l:directory = g:unite_source_grep_default_dir
endif
let l:candidates = split(
\ unite#util#system(printf(
\ 'grep %s %s %s',
\ a:context.input,
\ l:directory,
\ l:extra_opts)),
\ "\n")
return map(l:candidates,
\ '{
\ "word": v:val,
\ "source": "grep",
\ "kind": "file",
\ "action__path": substitute(v:val, "\:.*", "", ""),
\ }')
endfunction
call unite#define_source(s:grep_source)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment