Thursday, May 3, 2012

Help Definine a Function & User command

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.





--
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: