我们知道作曲家在标准的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
答案 0 :(得分:2)
Vimscript中没有explode()
。你的意思是expand()
。
此外,您可以通过system()
执行外部命令,或使用:!
命令,但不能同时执行两者。因此"!grep "
应该只是"grep "
。
最后,您应该使参数处理对奇怪的文件名更加健壮。使用shellescape(l:currentWord)
和fnameescape(l:fileName)
。