Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error characters in vimrc function

Tags:

vim

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.

The 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?

Thanks advance..

like image 684
Rafael Soufraz Avatar asked Jul 13 '15 17:07

Rafael Soufraz


People also ask

What does%R mean in vimrc?

%R – Displays the read-only flag. %b – Shows the ASCII/Unicode character under cursor. 0x%B – Shows the hexadecimal character under cursor. %l – Display the row number. %c – Display the column number. %p%% – Show the cursor percentage from the top of the file. Type help: statusline for more information. This is the complete .vimrc file.

Why does Vim have a problem with trailing characters?

Vim complains about "trailing characters" because you give it erroneous commands like: that contain too much junk and thus can't be parsed correctly. Vim uses " for comments. If you didn't already, do $ vimtutor as many times as needed to get the basics right.

Why can't I comment out a line in Vim?

Every line in your virmc is an Ex command. :# is an Ex command that prints lines so it can't be used for comments. Vim complains about "trailing characters" because you give it erroneous commands like: that contain too much junk and thus can't be parsed correctly. Vim uses " for comments.

How do I see cursor percentage in vimrc?

%c – Display the column number. %p%% – Show the cursor percentage from the top of the file. Type help: statusline for more information. This is the complete .vimrc file.


1 Answers

Instead of

exec 'normal :%s/(, /(/g'

You should just do

:%s/(, /(/g

Along with fixing the ^M and ^[ issues that should solve your problem.

like image 169
Dhruva Sagar Avatar answered Sep 30 '22 15:09

Dhruva Sagar