Created
January 25, 2015 16:09
-
-
Save gosukiwi/fb919a76164e3927b581 to your computer and use it in GitHub Desktop.
Execute vimgrep and open results using <Leader>g
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vim Finder plugin | |
" Wrapper around Vim's grep to make things easier | |
" Author: Federico Ramirez <[email protected]> | |
" 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