I'm trying to run a function that is in my vimrc to insert dependencies in a php class.
The script must enter a parameter type hinting in the construct of my class and assign the result of this parameter to an attribute of the local class.
I'm using Linux and I found in some posts that these types of characters that are in the function are not used to Linux. But for Mac.
Script php before run the function:
<?php
use Something\AnotherClass;
class MyClass {
public function __construct(AnotherClass $anotherClass)
{
$this->anotherClass = $anotherClass;
}
}
Script php after run the function:
<?php
use Something\AnotherClass;
use Something\OtherClass;
class MyClass {
public function __construct(AnotherClass $anotherClass, OtherClass $otherClass)
{
$this->anotherClass = $anotherClass;
$this->otherClass = $otherClass;
}
}
The vimrc function:
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
And when I try to run this function I get:
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
What is exactly this special chars?
How can I fixed this and is there some reference to learn about this chars?
normal!
with the exclamation mark, in order to use only internal vim commands and not commands defined by yourself (or others). Although, it seems as if your first executed normal mode command uses a command (:H
) that either you or someone else defined (e.g. in a plugin). Your last normal mode command should use the exclamation mark, at least.exec
command performs four or five edits: I suggest you split the command into the separate edits, instead of having one command doing all of them. This will help greatly in locating errors.