-
-
Save benjamin-frazier/caee199145f7060833d06d6da339e663 to your computer and use it in GitHub Desktop.
vim find from hades
This file contains hidden or 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
'Find' : 'find')<CR> | |
" Find file in current directory and edit it. | |
function! Find(name) | |
let l:list=system("find . -type f | grep -i '".a:name."' | perl -ne 'print \"$.\\t$_\"'") | |
" let l:list=system("find . -iname '".a:name."' | perl -ne 'print \"$.\\t$_\"'") | |
" replace above line with below one for gvim on windows | |
" let l:list=system("find . -name ".a:name." | perl -ne \"print qq{$.\\t$_}\"") | |
let l:num=strlen(substitute(l:list, "[^\n]", "", "g")) | |
if l:num < 1 | |
echo "'".a:name."' not found" | |
return | |
endif | |
if l:num != 1 | |
echo l:list | |
let l:input=input("Which ? (CR=nothing)\n") | |
if strlen(l:input)==0 | |
return | |
endif | |
if strlen(substitute(l:input, "[0-9]", "", "g"))>0 | |
echo "Not a number" | |
return | |
endif | |
if l:input<1 || l:input>l:num | |
echo "Out of range" | |
return | |
endif | |
let l:line=matchstr("\n".l:list, "\n".l:input."\t[^\n]*") | |
else | |
let l:line=l:list | |
endif | |
let l:line=substitute(l:line, "^[^\t]*\t./", "", "") | |
execute ":e ".l:line | |
endfunction | |
command! -nargs=1 Find :call Find("<args>") | |
:cabbrev find <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment