Skip to content

Instantly share code, notes, and snippets.

@gosukiwi
Created January 25, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gosukiwi/fb919a76164e3927b581 to your computer and use it in GitHub Desktop.
Save gosukiwi/fb919a76164e3927b581 to your computer and use it in GitHub Desktop.
Execute vimgrep and open results using <Leader>g
" Vim Finder plugin
" Wrapper around Vim's grep to make things easier
" Author: Federico Ramirez <fedra.arg@gmail.com>
" Licence: MIT
" Give the user a chance to not load the plugin, also discard the possibility
" of loading it more than once
if exists("g:loaded_finder")
finish
endif
let g:loaded_finder = 1
" Save the compability mode, set to no compatible and reset once we are done
let s:save_cpo = &cpo
set cpo&vim
" <Leader>g maps to <Plug>FinderGrep if not defined already in .vimrc
if !hasmapto('<Plug>FinderGrep')
map <unique> <Leader>g <Plug>FinderGrep
endif
" Map <Plug>FinderGrep to <SID>Grep
noremap <unique> <script> <Plug>FinderGrep <SID>Grep
" Map <SID>Grep to function call Grep
noremap <SID>Grep :call <SID>Grep()<CR>
" Grep function itself, simply asks for regex and perform search. Show results
" as soon as it's done searching
function s:Grep()
let filter = input("Search in project: ")
execute "vimgrep /" . filter . "/gj **/*"
execute "cw"
endfunction
" Return compatibility mode to the value it was before
let &cpo = s:save_cpo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment