Last active
December 25, 2015 15:19
-
-
Save danchoi/6996870 to your computer and use it in GitHub Desktop.
Lightweight Vim functions and keybindings for Rails project navigation
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
" Home-brewed Rails file-finder: | |
" Type :OP followed by a string fragment, and the app,test,spec,lib,config,db | |
" directories will be searched for files that match that string. | |
" Press TAB or shift-TAB to move through matches, and ENTER to open the file | |
" shown. | |
command -complete=custom,FasterOpenFunc -nargs=1 OP call s:faster_open(<f-args>) | |
func! FasterOpenFunc(A,L,P) | |
return system("find app test spec lib config db -name '*".a:A."*' 2>/dev/null | awk -F / '{print $NF \" -> \" $0}'") | |
endfun | |
" Shortcut for finding all matches for keyword under cursor in a Rails project. | |
" Put cursor over word and press <leader>g | |
func! s:vimgrep_shortcut() | |
let w = expand("<cword>") | |
exec "vimgrep ".w." app/**/* lib/**/* " | |
:cl | |
endfunc | |
nnoremap <leader>g :call <SID>vimgrep_shortcut()<CR> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment