vim9script def MyFunc() echom "hello" enddef command! MyCmd MyFunc()
vim -g --clean +'source test.vim':MyCmd
hello
:command MyCmd
Name Args Address Complete Definition
MyCmd 0 MyFunc()
call MyFunc()
E117: Unknown function: MyFunc
Functions assigned to commands are globally visible.
8.2.4394
GUI
No response
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
Functions assigned to commands are globally visible.
Why should a function be made implicitly global, simply because it can be called from a user-defined command?
Note that if you want a function to be explicitly global, you can prefix its name with g: in its header:
def g:MyFunc()
^^
Test:
vim9script def g:MyFunc() echomsg 'hello' enddef command MyCmd g:MyFunc() MyCmd feedkeys(":call MyFunc()\<Cr>")
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
Why should a function be made implicitly global, simply because it can be called from a user-defined command?
For example I want to rename a command defined by a plugin. I can do that for legacy vim plugins but it's not possible for vim9 plugins.
Note that if you want a function to be explicitly global, you can prefix its name with g: in its header:
This will not work for commands/functions defined by 3rd party vim9 plugins.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
For example I want to rename a command defined by a plugin
How about this:
command Renamed OldName
Test:
vim9script def MyFunc() echomsg 'hello' enddef command MyCmd MyFunc() MyCmd command Renamed MyCmd Renamed
hello
hello
I can do that for legacy vim plugins but it's not possible for vim9 plugins.
You can do that if the command calls a global function, but I don't think you can do that if it calls a script-local one.
For example, suppose a third-party plugin provides this :Cmd:
function s:Func()
echomsg 'hello'
endfunction
command Cmd call s:Func()
How would you rename Cmd into Renamed from a different script?
This will not work for commands/functions defined by 3rd party vim9 plugins.
But by default, items are local to the script where they are defined; including functions. It wouldn't make sense to make an exception for a function which is called by a user-defined command.
Alternatively, maybe we would need a new cmdarg() function, similar to maparg(). It could return the rhs of an arbitrary user-defined command. You could use it like so:
execute printf('command Renamed %s', cmdarg('OldName'))
Would that help?
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
How about this:
command Renamed OldName
It is a bit more complicated than this. I would not want an alias to a command, but to rename a command for real, so the old command disappears. There are plugins that define many similar commands, so using command completion becomes very difficult. So I would like to only keep some commands visible to completion and rename other commands (so that I could still use them in mappings).
With legacy vim, I could define a new command and delete the old command.
You can do that if the command calls a global function, but I don't think you can do that if it calls a script-local one.
I can do that for any commands defined in legacy script using script id. That's a bit difficult to do but still doable.
Alternatively, maybe we would need a new cmdarg() function, similar to maparg(). It could return the rhs of an arbitrary user-defined command.
I think that would be great solution. I could use the rhs in a new command and delete the old command.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
So, you would load a plugin, and then delete commands it defined.
That's a bit nasty. I can imagine Plugins are not prepared for this kind of use.
Making the function global is not desired, it should be private to the plugin.
If you would get the argument of the command and define a new command with that, it won't work, since the command is not defined in the script where the function is located. Unlike mappings, the function name is not expanded to the form.
The best solution I see is that the plugin provides a way to specify the command names you like.
E.g. for the "foobar" plugin set "g:foobar_that_name" to "MyCmdName".
The plugin would then need to do something like:
if exists('g:foobar_tat_name')
exe 'command ' .. g:foobar_that_name .. ' ThatFunction()'
else
command ThatCommand ThatFunction()
endif
More generally, using a dictionary to specify the configuration for the plugin would be a generic solution.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
I would not call it nasty. Commands were always for users, not for plugin internals. I'm sorry if I had a wrong picture.
The best solution I see is that the plugin provides a way to specify the command names you like.
E.g. for the "foobar" plugin set "g:foobar_that_name" to "MyCmdName".
That is a bit too much to ask from plugin developers.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
I agree that deleting commands may still break some plugins.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
Closed #9907.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
I know that introducing new options is frowned upon, considering that we already have a lot, but a new 'cmdignore' option would fix the real issue, which was described here:
There are plugins that define many similar commands, so using command completion becomes very difficult.
So, for example, if a user has 2 plugins installing a bunch of commands starting with the prefixes Foo and Bar, they could tell Vim that they don't want any of them to be suggested after pressing Tab while on the command-line:
set cmdignore=Foo*,Bar*
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
I know that introducing new options is frowned upon, considering that we already have a lot, but a new
'cmdignore'option would fix the real issue, which was described here:There are plugins that define many similar commands, so using command completion becomes very difficult.
So, for example, if a user has 2 plugins installing a bunch of commands starting with the prefixes
FooandBar, they could tell Vim that they don't want any of them to be suggested after pressing Tab while on the command-line:set cmdignore=Foo*,Bar*
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
With the support for fuzzy completion of command names (set 'wildoptions'
to 'fuzzy'), it should be easy to complete command names ignoring case and to complete
names after typing a few characters anywhere in the name.
While the new fuzzy value of the 'wildoptions' is great to increase the number of suggestions, I think the OP is looking for the opposite: a way to decrease the number of suggestions, by pruning arbitrary Ex commands.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you commented.![]()
Yes, hiding some commands from the completion would be a solution to my original problem.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you commented.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.![]()