vim-plug icon indicating copy to clipboard operation
vim-plug copied to clipboard

Why use `plug#()` as a function name ?

Open sisrfeng opened this issue 1 year ago • 1 comments

The function name plug#() seems a little strange, and it's my first time to see such name in vimL. Is it like plug#a_func(), but a_func becomes empty string? Is there any trick that you use such a name? https://github.com/junegunn/vim-plug/blob/8fdabfba0b5a1b0616977a32d9e04b4b98a6016a/plug.vim#L266

sisrfeng avatar Jul 28 '22 05:07 sisrfeng

The function name plug#() might seem a little strange, but in VimL (Vim Scripting Language), it's a valid function name. It's not a call to another function like a_func(), but rather it's the actual name of the function being defined.

In VimL, function names can contain special characters like #, and they are not limited to alphanumeric characters. As a plugin author, I might use such names to avoid potential naming conflicts with other functions or scripts.

To understand how the function works, I would need to look at its implementation within the vim-plug plugin codebase. Unfortunately, the provided code snippet only shows the command definition, not the actual function implementation.

To find out how the function works, I would need to locate its implementation within the vim-plug plugin codebase, typically in the same file or in a file included by the plugin. From the command definition, I can see that the function takes arguments () and is called when the Plug command is executed in Vim.

Regarding naming conventions, there is no strict rule for using special characters like # in function names in VimL. However, it's common for plugin authors like me to use such characters to indicate that the function is part of a plugin and not a standard Vim function.

In summary, the function name plug#() is valid VimL syntax and is used in the context of the vim-plug plugin. To understand its behavior fully, I would need to find its implementation within the plugin's codebase.

FrodoBaggins74524 avatar Jul 30 '23 04:07 FrodoBaggins74524

  • It's a part of the public API so I have two choices. 1. a name that starts with an uppercase letter, or 2. a name that starts with plug# prefix that matches the name of the file.
  • Other functions have plug# prefix, so using the prefix is more consistent
  • It's a function backing Plug command, so I decided to name it plug# to match that. Yeah, it's a bit weird but I liked it better than something like plug#add.

junegunn avatar Mar 15 '24 11:03 junegunn