Skip to content

Abbreviation "ap" about using the append command #17893

Closed

Description

@dai475694450

Steps to reproduce

When a user-defined command starts with "ap" (e.g., ":apple"), Vim incorrectly interprets "ap" as an abbreviation for the "append" command inside a function body, producing a confusing error message. This behavior is inconsistent with how other commands that violate the "must start with an uppercase letter" rule are handled.
For example, consider two scenarios:

  1. Define a user command ":apple" in "apple.vim". When called inside a function, Vim throws a misleading error that confuses developers and makes debugging difficult.
Image Image
  1. Define a user command ":peer" in "peer.vim". When called inside a function, Vim correctly reports that user-defined command names must start with an uppercase letter.
Image Image

Root Cause Analysis:
The issue appears to stem from the "get_function_body()" function in "src/userfunc.c". Specifically, this line of code seems to be the cause:
“if (!vim9_function && ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p'))“
This check, combined with the logic for
"vim9_function" ("int vim9_function = eap->cmdidx == CMD_def || eap->cmdidx == CMD_block;")
incorrectly identifies any command starting with "ap" as the "append" command within a legacy function body.

Expected behaviour

I would like to suggest adding a new option to disable this specific abbreviation parsing within functions.For example, a new option "set parsecommand" ,The check in "src/userfunc.c" could then be modified to respect this option:
"if (!vim9_function && !p_pcmd && ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p')) "
Please see the screenshot below for a illustration:

Image Image

Version of Vim

Vim Versions: All versions from 8.x to 9.x.

Environment

All operating systems.

Logs and stack traces

Activity

  1. habamax commented on Aug 1, 2025

    @habamax
    Contributor

    I would like to suggest adding a new option to disable this specific abbreviation parsing within functions.For example, a new option "set parsecommand"

    There is probably a better way to handle the issue other than creating a new parsecommand option.

  2. habamax commented on Aug 1, 2025

    @habamax
    Contributor

    The error is misleading here, indeed (E1145):

    func Hello()
        command apple :echo "hello apple"
        :apple
    endfunc
    
    call Hello()
    

    If you do the same in vim9script, it is better but still, I would expect E183 and then E476:

    vim9script
    
    def Hello()
        command apple :echo "hello apple"
        :apple
    enddef
    
    Hello()
    
    Image
  3. dkearns commented on Aug 1, 2025

    @dkearns
    Contributor

    Thanks for the report. Your proposed solution seems rather outlandish. If it was generated by an LLM it would be a good idea to add that to the report.

    I only skimmed the code but I suspect we can get away with using checkforcmd() there to more accurately check for :append and friends.

  4. assigned and unassigned on Aug 1, 2025
  5. h-east commented on Aug 3, 2025

    @h-east
    Contributor

    @habamax

    If you do the same in vim9script, it is better but still, I would expect E183 and then E476:

    In the case of the def function in Vim9 script, this is expected because there are "side effects of compiling a function."
    See :h vim9-user-command

  6. h-east commented on Aug 3, 2025

    @h-east
    Contributor

    @dkearns You are self-assigning. Is that intended?

    For now, I'll leave the patch here. --> It was a useless patch so I deleted it.

  7. dkearns commented on Aug 3, 2025

    @dkearns
    Contributor

    Yes, I have a fix for this. Thanks.

  8. dai475694450 commented on Aug 6, 2025

    @dai475694450
    Author

    @dkearns @h-east
    That's great to hear. Thank you for looking into this and proposing a solution. Appreciate you taking this on!

  9. h-east commented on Aug 8, 2025

    @h-east
    Contributor

    @dkearns Sorry. I submitted a pull request first.
    Could you please review it?
    If you don't like it, you can close my PR and submit your own.

  10. added a commit that references this issue on Aug 8, 2025
    efd83d4
  11. added 2 commits that reference this issue on Aug 8, 2025
    a49dd84
    e7dfbf1
  12. added 2 commits that reference this issue on Aug 8, 2025
    f5c42e3
    ced4eed
  13. added a commit that references this issue on Aug 23, 2025
    0e25fb4
  14. added a commit that references this issue on Sep 7, 2025
    385b23a
  15. added a commit that references this issue on Sep 27, 2025
    be081dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions