Skip to content

Comment.nvim throws [Comment.nvim] nil when using vim.pack #530

Open

Description

@Hello-LuisWu

I am using Neovim's built-in vim.pack to install and load Comment.nvim.

The default gcc mapping works correctly, including for Zsh files. However, when I configure custom keymaps through toggler, opleader, or vim.keymap.set(), commenting fails with:

[Comment.nvim] nil

For example:

vim.pack.add({
"https://github.com/numToStr/Comment.nvim",
})

local cm = require("Comment")

cm.setup({
toggler = {
line = "<C-\>",
block = "\",
},

opleader = {
    line = "<C-\\>",
    block = "<leader>\\",
},

})

The default mapping:

gcc

works correctly on the same Zsh file.

I also verified that the Zsh filetype and commentstring are correct:

:set filetype?
filetype=zsh

:set commentstring?
commentstring=# %s

I tried configuring the Zsh commentstring explicitly:

local ft = require("Comment.ft")
ft.set("zsh", "#%s")

but this does not resolve the error.

I also tried creating the mapping manually with vim.keymap.set() and encountered the same:

[Comment.nvim] nil

Therefore, the issue does not appear to be related to the Zsh filetype or its commentstring. The default gcc mapping works, while custom mappings consistently trigger the error.

Environment
Neovim: 0.12.x
Plugin manager: built-in vim.pack
Plugin: numToStr/Comment.nvim
Filetype: zsh
Expected behavior

Custom mappings configured through toggler, opleader, or vim.keymap.set() should work in the same way as the default gcc mapping.

Is there a known compatibility issue with custom mappings when Comment.nvim is loaded using Neovim's vim.pack? What is the recommended configuration or workaround?

Activity

  1. 0xEFFF commented on Sep 5, 2026

    @0xEFFF

    I ran into the same issue in tmux config file. Looks like this repo isn't maintained anymore, so I spent some time trying out a few alternatives, figured I'd share this in case it helps you:

    1. use the branch from this MR fix: take into account a nil returned by get_parser #518:
    vim.pack.add({
      {
        src = "https://github.com/faergeek/Comment.nvim",
        version = "nvim-0.12-compatibility",
      },
    })
    1. Just drop the plugin, since Neovim now has built-in line commenting (e.g. gc, gcc) and also supports treesitter-based commentstring parsing. I tried it out and it works realy great -- only downside is it doesn't support block comments (e.g. gb, gbc), and it skips empty lines when commenting. See :help commenting
    2. Use mini.comment -- pretty much the same as Neovim's bulit-in, but it can comment out empty lines. However, no block comment support either.
    3. Use celeste_comment.nvim, supports both gc, gb and it's actively maintained.
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