Skip to content

Commit 1172796

Browse files
author
Gianluca Arbezzano
committed
Merge pull request #13 from sensorario/composer-knows
Update vim-composer.vim
2 parents 22bfc5f + 52f4ff4 commit 1172796

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ In this example after every `composer install` I exec a ctags generation
2929
This command open `composer.json`
3030

3131

32+
```vim
33+
:ComposerKnowWhereCurrentFileIs
34+
```
35+
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:
36+
37+
map <F6> :call ComposerKnowWhereCurrentFileIs()<CR>
38+
39+
3240
## Install
3341
```vim
3442
Bundle 'vim-php/vim-composer'

plugin/vim-composer.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,17 @@ function! s:ComposerInstallFunc(arg)
5454
exe "call ".g:composer_install_callback."()"
5555
endif
5656
endfunction
57+
58+
function! ComposerKnowWhereCurrentFileIs()
59+
let l:currentWord = expand('<cword>')
60+
let l:command = "grep " . l:currentWord . " ./vendor/composer -R | awk '{print $6}' | awk -F\\' '{print $2}'"
61+
let l:commandFileFound = l:command . ' | wc -l'
62+
let l:numberOfResults = system(l:commandFileFound)
63+
if l:numberOfResults == 1
64+
let l:fileName = system(l:command)
65+
let l:openFileCommand = 'tabe ' g:project_path . l:fileName
66+
exec l:openFileCommand
67+
else
68+
echo "No unique file found in composer's generated files"
69+
endif
70+
endfunction

0 commit comments

Comments
 (0)