VimL:"使用"当光标在其名称上时,composer打开类文件

时间:2015-05-18 12:00:49

标签: vim

我们知道作曲家在标准的psr-0

中知道类的路径
map <F6>  :call ComposerKnowWhereCurrentFileIs()<CR>

function! ComposerKnowWhereCurrentFileIs()
    let l:currentWord = explode('<cword>')
    let l:command = "!grep " . l:currentWord . " vendor/composer -R | awk '{print $6}' | awk -F\' '{print $2}'"
    let l:fileName = system(l:command)
    let l:openFileCommand = 'tabe ' . l:fileName
    exec l:openFileCommand
endfunction

但是,......当我按下键

时,我看到了这个输出
Error detected while processing function ComposerKnowWhereCurrentFileIs:
line    1:
E117: Unknown function: explode
E15: Invalid expression: explode('<cword>')
line    2:
E121: Undefined variable: l:currentWord
E15: Invalid expression: "!grep " . l:currentWord . " vendor/composer -R | awk '
{print $6}' | awk -F\' '{print $2}'"
line    3:
E121: Undefined variable: l:command
E116: Invalid arguments for function system(l:command)
E15: Invalid expression: system(l:command)
line    4:
E121: Undefined variable: l:fileName
E15: Invalid expression: 'tabe ' . l:fileName
line    5:
E121: Undefined variable: l:openFileCommand
E15: Invalid expression: l:openFileCommand

1 个答案:

答案 0 :(得分:2)

Vimscript中没有explode()。你的意思是expand()

此外,您可以通过system()执行外部命令,使用:!命令,但不能同时执行两者。因此"!grep "应该只是"grep "

最后,您应该使参数处理对奇怪的文件名更加健壮。使用shellescape(l:currentWord)fnameescape(l:fileName)