Skip to content

Instantly share code, notes, and snippets.

@jarednorman
Last active May 6, 2018 21:27
Show Gist options
  • Save jarednorman/9c56fd9eb14784e5ac277afb861fd8be to your computer and use it in GitHub Desktop.
Save jarednorman/9c56fd9eb14784e5ac277afb861fd8be to your computer and use it in GitHub Desktop.
Search for a gem in the current project, and then search for (and open) a file within it (from Vim, requires fzf.vim)
" Gem search
function! GemSearch()
call fzf#run(fzf#wrap({'source': "bundle list | sed '1d;$d' | cut -d ' ' -f 4", 'sink': {gem -> GemFileSearch(gem)}}))
endfunction
function! GemFileSearch(gem)
let gemdir = substitute(system("bundle show " . a:gem), '\n\+$', '', '')
call fzf#run(fzf#wrap({'source': 'rg --files ' . gemdir . ' --color never | sed -e "s#^' . gemdir . '/##"', 'dir': gemdir}))
endfunction
nnoremap <leader>gf :call GemSearch()<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment