1

I have a function like this in autoload/foo/bar.vim:

function! foo#bar#do_stuff(...) abort
  " do stuff
  return
endfunction

Is it possible to create an "alias" for this function, without defining a wrapper function and passing args with call()?

I tried this in autoload/quux.vim:

let quux#do_stuff = function('foo#bar#do_stuff')

But I got an error saying that "Funcref variable name must start with a capital".

Is there some other way to define an alias like this? Or must I write an actual wrapper function?

2 Answers 2

2

May I ask why do you want to address this function through another name?

If you need an indirection

let SomeRef = function('foo#bar#do_stuff')

works correctly. You can define as many variables as you want (that respect Vim naming policy for function-reference variables), but you won't be able to define functions this way.

2
  • 1
    I wanted to create an alias for backward compatibility in a plugin, so creating an alias with the wrong name doesn't help. So I want it to be autoloaded and namespaced in the same way as the other functions in the same file. So the answer is "no, it's not possible" then? Apr 15, 2022 at 19:31
  • 1
    @shadowtalker Indeed. As far as I know, this is not possible. In my plugins, I kept the old function, add a "notify once" message about the deprecation, and forward the call to the new function, like I do here: github.com/LucHermitte/lh-vim-lib/blob/… Apr 16, 2022 at 23:42
0

As per Luc Hermitte, this is indeed not possible with Vimscript.

You should upvote their answer, but I am posting this so I can mark the question as "answered".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.