in vimscript, sometimes i pass argument using method. the syntax is like…
- User
in vimscript, sometimes i pass argument using method. the syntax is like "'hello'->PringString()". but my question is using this syntax can i pass multiple arguments?
- Assistant
No, you cannot pass multiple arguments using the syntax "'hello'->PringString()".
In Vimscript, the "->" operator is used to call a method or function on an object. However, this syntax is limited to passing a single argument to the method.
If you need to pass multiple arguments to a method, you can use a different syntax. Here's an example:
let message = 'hello' call message.PrintString('foo', 'bar')In the above example, the method
PrintString()is called on themessageobject, and it is passed two arguments:'foo'and'bar'. Thecallcommand is used to invoke the method.Alternatively, if you want to pass a list of arguments, you can use the
call()function along with thecall()function. Here's an example:let args = ['foo', 'bar'] echo call(message, 'PrintString', args)In this case, the method
PrintString()is called on themessageobject, and theargslist is passed as arguments. Thecall()function is used to dynamically invoke the method with the specified arguments.