Skip to content

Instantly share code, notes, and snippets.

@c-j-j
Created January 22, 2016 09:54
Show Gist options
  • Save c-j-j/5bc171a29973f5310f93 to your computer and use it in GitHub Desktop.
Save c-j-j/5bc171a29973f5310f93 to your computer and use it in GitHub Desktop.
Find Ruby File Usages With Vim
function! RemoveLibPrefix(path)
let shortenedPath = split(a:path, "/")[1:]
return join(shortenedPath, "/")
endfunction
function! FindCurrentFileUsage()
let filePath = RemoveLibPrefix(@%)
let rubyPath = substitute(filePath, ".rb", "", "")
exec "silent grep! " . rubyPath . " **/*.rb"
exec "copen"
exec "redraw!"
endfunction
command! FindCurrentFileUsage call FindCurrentFileUsage()
nnoremap ,gcf :FindCurrentFileUsage<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment