我正在尝试运行我的vimrc中的函数来在php类中插入依赖项.
脚本必须在我的类的构造中输入参数类型提示,并将此参数的结果分配给本地类的属性.
我正在使用Linux,我在一些帖子中发现函数中的这些类型的字符不适用于Linux.但对于Mac.
功能:
function! AddDependency()
let dependency = input('Var Name: ')
let namespace = input('Class Path: ')
let segments = split(namespace, '\')
let typehint = segments[-1]
exec 'normal gg/construct^M:H^Mf)i, ' . typehint . ' $' . dependency . '^[/}^>O$this->^[a' . dependency . ' = $' . dependency . ';^[?{^MkOprotected $' . dependency . ';^M^[?{^MOuse ' . namespace . ';^M^['
" Remove opening comma if there is only one dependency
exec 'normal :%s/(, /(/g'
endfunction
Run Code Online (Sandbox Code Playgroud)
当我尝试运行此功能时,我得到:
Error detected while processing function AddDependency:
line 10:
E115: Missing quote: 'normal :%s/(, /(/g
E15: Invalid expression: 'normal :%s/(, /(/g
Press ENTER or type command to continue
Run Code Online (Sandbox Code Playgroud)
这个特殊的字符是什么?
我该如何解决这个问题,是否有一些参考来了解这个字符?
谢谢提前..
代替
exec 'normal :%s/(, /(/g'
Run Code Online (Sandbox Code Playgroud)
你应该这样做
:%s/(, /(/g
Run Code Online (Sandbox Code Playgroud)
以及解决^M应该^[解决您的问题的问题。