Skip to content

[audit] ]c / [c treesitter-textobjects keymaps shadow native diff-mode jump #236

Description

@stanfish06

What

lua/config/plugin_config.lua:336–341 maps ]c / [c (and ]C / [C) to treesitter-textobjects "next/prev class start/end" via nvim-treesitter-textobjects.move. These are global normal-mode keymaps.

Vim's built-in ]c / [c jump to the next/previous diff change in diff mode (:help ]c). Once the treesitter-textobjects mapping is registered, diff-mode navigation via ]c / [c is silently broken for any buffer that loads the treesitter-textobject module.

Where

  • lua/config/plugin_config.lua:336]cgoto_next_start("@class.outer")
  • lua/config/plugin_config.lua:339[cgoto_previous_start("@class.outer")

Why it matters

The config already maps ]g / [g to gitsigns hunk navigation, so the common use case (git hunk jumping) is covered. But Neovim's native ]c / [c are also used in:

  • :diffthis / vimdiff workflows
  • DiffviewOpen with a split showing actual diff buffers (diffview uses native diff mode internally)

In those contexts, ]c will jump to a class boundary instead of the next diff change, which is silently wrong and hard to diagnose.

Recommended action

Remap the class textobjects to keys that don't collide with built-in diff navigation. Common alternatives:

-- option A: use ]a / [a (currently unbound)
vim.keymap.set({"n","x","o"}, "]a", function() move.goto_next_start("@class.outer", ...) end)
vim.keymap.set({"n","x","o"}, "[a", function() move.goto_previous_start("@class.outer", ...) end)

-- option B: add a mode guard so ]c only applies outside diff mode
vim.keymap.set({"n","x","o"}, "]c", function()
    if vim.wo.diff then
        vim.cmd("normal! ]c")
    else
        move.goto_next_start("@class.outer", "textobjects")
    end
end)

Option B preserves the muscle memory of ]c for class jumps while restoring diff behaviour.

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