diff --git a/README.md b/README.md index 41a62bd..a116a41 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,14 @@ In this example after every `composer install` I exec a ctags generation This command open `composer.json` +```vim +:ComposerKnowWhereCurrentFileIs +``` +This function aims to help you to load files without using ctag. Grep current word inside composer autogenerated files, and if only one occurrence is found, opens file in another tab. If zero or more occurrences are found, simply echoes a string to advice you. To use this in your .vimrc file, just remap function. For example you can use: + + map :call ComposerKnowWhereCurrentFileIs() + + ## Install ```vim Bundle 'vim-php/vim-composer' diff --git a/plugin/vim-composer.vim b/plugin/vim-composer.vim index 7c657f3..1fc3d61 100644 --- a/plugin/vim-composer.vim +++ b/plugin/vim-composer.vim @@ -54,3 +54,17 @@ function! s:ComposerInstallFunc(arg) exe "call ".g:composer_install_callback."()" endif endfunction + +function! ComposerKnowWhereCurrentFileIs() + let l:currentWord = expand('') + let l:command = "grep " . l:currentWord . " ./vendor/composer -R | awk '{print $6}' | awk -F\\' '{print $2}'" + let l:commandFileFound = l:command . ' | wc -l' + let l:numberOfResults = system(l:commandFileFound) + if l:numberOfResults == 1 + let l:fileName = system(l:command) + let l:openFileCommand = 'tabe ' g:project_path . l:fileName + exec l:openFileCommand + else + echo "No unique file found in composer's generated files" + endif +endfunction