Thursday, May 3, 2012

Re: Help Definine a Function & User command

On Thursday, May 3, 2012 11:09:15 AM UTC-5, howardb21 wrote:
> A while back I voiced interest and got help in disabling abbreviations, when I
> was on the : command line. I want to write functions to do this, in a little
> different way -- but need some help in basic function defining. Speciflcally,
> I am not sure how function arguments are referenced a function's
> definition.
>
> I want to do something like this:
>
> function! ABB(lhs, rhs)
> if getcmdtype() == ':'
> return a:lhs
> else
> return a:rhs
> endif
> endfu
> function! Rearrange(first,second)
> exe 'ab <expr>' a:first Abbr('a:first','a:second')
> endfu
> command =nargs=3 Ab call Rearrange(<s-args>) ihs rhs
>
> If all this works, the user command
>
> Ab ihs rhs
>
> would create this abbreviation:
>
> ab <expr> ihs Abbr('ihs','rhs')
>
> Than ihs would be expanded to rhs, as long as it was not being entered on the
> : command line. Otherwise it expands to itself.
>
> I am not sure of is whether a:first and a: second are the right ways to
> have my variables in Rearrange() evaluated and used in the definition. I'n
> not clear at all about user defined commands: What in these commands are
> considered ``commands'' and what on the command line are considered
> ``arguments''? Are the expressions referred by by <s-args> every item
> after the name of the new command? If so, I would need to refer, somehow, to
> argments 3 and 4 in the command definition, and not use <s-args> for the
> arguments.

1. I am not sure where you found <s-args>. I think you want <f-args>. See :help <f-args> for what it does.
2. your line exe 'ab <expr>' a:first Abbr('a:first','a:second') calls a function which does not exist in the script you gave. I assume you meant ABB.
3. The same line does not do at all what you wish. You probably want to quote the name of the function, but use the values of the variables. You're doing the opposite.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: