Skip to content

Error message "[Comment.nvim] nil" when plugin is used with vim.pack #517

Open

Description

@rseichter

I am experimenting with moving from Lazy to the new vim.pack plugin manager in Neovim nightly. Looks mostly OK, but I may be configuring Comment.nvim incorrectly. When using key bindings like gcc, all I get is the error message "[Comment.nvim] nil", which is not too helpful in itself.

How does one correctly configure this plugin for vim.pack? The following does not seem to work:

return {
  'numToStr/Comment.nvim',
  config = function()
    require('Comment').setup()
  end,
}

Activity

  1. babelfish commented on Mar 20, 2026

    @babelfish

    I'm seeing the same thing while using lazy in neovim nightly.

  2. rseichter commented on Mar 20, 2026

    @rseichter
    Author

    Oh. I did not consider that this might be an issue with the nightly Neovim build in general. I experienced the problem for the first time after I started my vim.pack tests.

  3. faergeek commented on Mar 21, 2026

    @faergeek

    Seems like it's caused by this change in neovim: neovim/neovim@fd1e019

  4. added a commit that references this issue on Mar 21, 2026
    9386e87
  5. rseichter commented on Mar 21, 2026

    @rseichter
    Author

    @faergeek Thanks for the fix, it works for me.

  6. miguelgrinberg commented on Apr 5, 2026

    @miguelgrinberg

    I also started getting this after I upgraded to Nvim 0.12. I don't think #518 is a good solution, as it just avoids using tree-sitter for the commenting logic, which is not ideal. The real problem (in my case at least) was that tree-sitter broke when I upgraded from 0.11 to 0.12.

    To fix tree-sitter, I had to move the nvim-treesitter plugin from the master branch to the main branch. The code in master is compatible with Nvim < 0.12 only, and the code in main is for 0.12. Unfortunately the configuration for the main branch changed in an incompatible way. This is what I found to work for me:

        {
            'nvim-treesitter/nvim-treesitter',
            lazy = false,
            branch = "main",
            build = ":TSUpdate",
            init = function()
                require('nvim-treesitter').install({ 'python', 'javascript', 'typescript', 'jsx', 'tsx', 'go', 'rust', 'html', 'css', 'lua', 'vim' })
            end,
        },

    In addition, the version in main requires a fairly recent version of the tree-sitter-cli tool to be installed. I took care of this by running:

    cargo install --locked tree-sitter-cli

    With this, comments started to work again, including the trickier cases like jsx/tsx files, which rely on tree-sitter contextual information to provide the correct commenting style.

    In my previous configuration I relied on the auto_install feature to ensure there was always a tree-sitter parser available. It does not appear to be a similar option for the most recent version of the plugin, so it is important to make sure all the languages that you need are explicitly loaded.

    Sadly, the nvim-treesitter repository has been archived just a couple of days ago, and I'm not sure what to do about that. But for the time being everything seems to work.

    I hope this helps others with the same issue!

  7. faergeek commented on Apr 6, 2026

    @faergeek

    I don't think #518 is a good solution, as it just avoids using tree-sitter for the commenting logic, which is not ideal

    Saying something is not a good solution just because it doesn't solve your particular problem is a bit rough, don't you think? Comment.nvim supports not only languages that are supported by tree-sitter. There is a ton of languages which do not have a tree-sitter parser. That "not good solution" makes it work in such cases.

  8. rseichter commented on Apr 6, 2026

    @rseichter
    Author

    @faergeek I wouldn't worry about the "not a good solution" comment. Your fix resolved my immediate issue, which is undoubtedly a good thing. I also believe in the old adage that perfect should not be allowed to stand in the way of good.

  9. miguelgrinberg commented on Apr 6, 2026

    @miguelgrinberg

    @faergeek apologies, my choice of words was terrible, and I had no intention to offend anyone. Your solution is good, as it is the only way to make things work when you do not have a tree-sitter grammar installed for your language.

  10. rseichter commented on May 6, 2026

    @rseichter
    Author

    @LongYinStudio Downgrading to Neovim 0.11 is not an option, what with vim.pack only being available in versions 0.12.0 and later. 😉

  11. rseichter commented on May 6, 2026

    @rseichter
    Author

    @LongYinStudio Now I have to ask: Did you even read the comments in this issue? The reason behind this problem is quite clear, and @faergeek made a fix available three weeks ago. I can see no mystery here.

  12. vijay-git-hub3 commented on May 18, 2026

    @vijay-git-hub3

    @faergeek Is there a way you can also add fix for block commenting? Its still returning nil.
    Its the only reason I haven't switched to mini.comment

  13. faergeek commented on May 18, 2026

    @faergeek

    @vijay-git-hub3 I've switched to mini.comment and I'm not really interested in fixing something I don't use anymore.

  14. ilan-schemoul commented on Jun 16, 2026

    @ilan-schemoul

    I have nvim 0.12.3 it doesn't work. I have lazy with zero config just basic setup. It just gives a warning "nil" with nothing else. I think it used to work on nvim 0.12 until recently. Either upgrading this plugin or going from 0.12 to 0.12.3 broke something but nothing works on my side.
    I have treesitter main branch with proper config, reinstalled every treesitter parser etc.

  15. 4k1k0 commented on Jul 4, 2026

    @4k1k0

    My setup: nvim 0.12.3

    I have some languages configured with this plugin:

    language works
    elixir nil
    erlang nil
    gleam nil
    go yes
    javascript nil
    lua nil
    python nil
    rust nil
    sh nil
    typescript nil
    yaml nil

    The plugin doesn't load automatically when nvim starts, to start the plugin I run:

    :lua require('Comment').setup()
    

    Once the plugin is loaded I can use it with .go files, but the rest of my configuration doesn't work.

    Here's my full configuration:

    require('Comment').setup(
      {
        ---Add a space b/w comment and the line
        padding = true,
        ---Whether the cursor should stay at its position
        sticky = true,
        ---Lines to be ignored while (un)comment
        ignore = nil,
        ---LHS of toggle mappings in NORMAL mode
        toggler = {
            ---Line-comment toggle keymap
            line = '<leader>c',
            ---Block-comment toggle keymap
            block = '<leader>C',
        },
        ---LHS of operator-pending mappings in NORMAL and VISUAL mode
        opleader = {
            ---Line-comment keymap
            line = '<leader>c',
            ---Block-comment keymap
            block = '<leader>C',
        },
        ---LHS of extra mappings
        extra = {
            ---Add comment on the line above
            above = 'gcO',
            ---Add comment on the line below
            below = 'gco',
            ---Add comment at the end of line
            eol = 'gcA',
        },
        ---Enable keybindings
        ---NOTE: If given `false` then the plugin won't create any mappings
        mappings = {
            ---Operator-pending mapping; `gcc` `gbc` `gc[count]{motion}` `gb[count]{motion}`
            basic = true,
            ---Extra mapping; `gco`, `gcO`, `gcA`
            extra = true,
        },
        ---Function to call before (un)comment
        pre_hook = nil,
        ---Function to call after (un)comment
        post_hook = nil,
      }
    )
    
    local ft = require('Comment.ft')
    
    ft.go = {'//%s', '//%s'}
    ft.javascript = {'//%s', '/*%s*/'}
    ft.yaml = '#%s'
    ft.rust = {'//%s', '/*%s*/'}
    ft.typescript = {'//%s', '/*%s*/'}
    ft.elixir = {'#%s', '#%s'}
    ft.erlang = {'%% %s', '%% %s'}
    ft.gleam = {'//%s', '//%s'}
    ft.lua = {'--%s', '--[[%s]]'}
    ft.sh = {'#%s', '#%s'}
    ft.python = {'#%s', '#%s'}
    ft.haskell = {'--%s', '{-%s-}'}

    I installed this plugin using the new package manager from nvim 0.12

    Note: I already tried changing the timeoutlen setting.

  16. Jouo commented on Jul 19, 2026

    @Jouo

    @miguelgrinberg nvim-treesitter got unarchived yesterday, is the fix that you described part of a PR or something?

  17. redvedev commented on Jul 27, 2026

    @redvedev

    It works for lua files, but for python I get the error

  18. darianmorat commented on Aug 17, 2026

    @darianmorat

    Found a workaround: using load = function() in the vim.pack spec and calling require("Comment").setup() there fixes the [Comment.nvim] nil error

  19. ayoubelmhamdi commented on Aug 23, 2026

    @ayoubelmhamdi

    A temporary solution is for any plugin fixed in the PR and not merged yet: use forke repo and setting branch
    from PR pages:

    Image
    {
        "faergeek/Comment.nvim",
        branch = "nvim-0.12-compatibility",
        opts = {},
    }
  20. added a commit that references this issue on Oct 2, 2026
  21. added a commit that references this issue on Oct 12, 2026
    06747fa
  22. added a commit that references this issue on Nov 8, 2026
    fc1b123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions