Skip to content

[Bug] Custom keymaps prefixed with <localleader> aren't available immediately after opening diffview #564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
garlicbreadcleric opened this issue Mar 21, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@garlicbreadcleric
Copy link

garlicbreadcleric commented Mar 21, 2025

Description

I have a following Lazy.nvim config for Diffview:

Config
{
  'sindrets/diffview.nvim',
  lazy = false,
  keys = {
    -- ...
  },
  opts = function()
    local actions = require('diffview.actions')
    return {
      -- ...
      keymaps = {
        view = {
          { 'n', '<tab>', actions.select_next_entry, { desc = 'Next file diff' } },
          { 'n', '<s-tab>', actions.select_prev_entry, { desc = 'Previous file diff' } },
          { 'n', '[x', actions.prev_conflict, { desc = 'Previous conflict' } },
          { 'n', ']x', actions.next_conflict, { desc = 'Next conflict' } },
          { 'n', '<localleader>xo', actions.conflict_choose('ours'), { desc = 'Accept ours' } },
          { 'n', '<localleader>xt', actions.conflict_choose('theirs'), { desc = 'Accept theirs' } },
          { 'n', '<localleader>xb', actions.conflict_choose('base'), { desc = 'Accept base' } },
          { 'n', '<localleader>xa', actions.conflict_choose('all'), { desc = 'Accept all' } },
          { 'n', '<localleader>Xo', actions.conflict_choose_all('ours'), { desc = 'Accept ours (whole file)' } },
          { 'n', '<localleader>Xt', actions.conflict_choose_all('theirs'), { desc = 'Accept theirs (whole file)' } },
          { 'n', '<localleader>Xb', actions.conflict_choose_all('base'), { desc = 'Accept base (whole file)' } },
          { 'n', '<localleader>Xa', actions.conflict_choose_all('all'), { desc = 'Accept all (whole file)' } },
        },
      },
    }
  end,
  main = 'diffview',
  setup = true,
}

(full config here, minimal config below)

When I do :DiffviewOpen, I expect the <localleader>xo etc keymaps to be available. However, which-key doesn't show them when I press <localleader>, and pressing <localleader>xo doesn't do anything. <tab> and <s-tab> keymaps are working though. If I then <c-w>h to the diffview sidebar and then <c-w>l back to the file diff, the keymaps become available.

Expected behavior

<localleader>-prefixed keymaps are available immediately after opening file diff via :DiffviewOpen

Actual behavior

<localleader>-prefixed keymaps only become available after switching to the sidebar and then back to file diff

Steps to reproduce

  1. :DiffviewOpen
  2. Try to use <localleader>-prefixed keymap
  3. Switch to sidebar and back
  4. Try to use a keymap again

Health check

Output of :checkhealth diffview
==============================================================================
diffview:                                   require("diffview.health").check()

Checking plugin dependencies ~
- OK nvim-web-devicons installed.

Checking VCS tools ~
- The plugin requires at least one of the supported VCS tools to be valid.
- OK Git found.
- OK Git is up-to-date. (2.43.0)
- WARNING Configured `hg_cmd` is not executable: 'hg'

Log info

Relevant info from :DiffviewLog
############################
### PUT LOG CONTENT HERE ###
############################

Neovim version

NVIM v0.11.0-dev-1775+g4a2a54f993
Build type: RelWithDebInfo
LuaJIT 2.1.1736781742

I think this was the case with stable Neovim too, lmk if you can't reproduce this on stable, I'll try to roll back and reproduce.

Operating system and version

Linux 6.8.0-55-generic x86_64 GNU/Linux

Minimal config

-- #######################################
-- ### USAGE: nvim --clean -u mini.lua ###
-- #######################################

local root = vim.fn.stdpath('run') .. '/nvim/diffview.nvim'
local plugin_dir = root .. '/plugins'
vim.fn.mkdir(plugin_dir, 'p')

for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

local plugins = {
  { 'nvim-web-devicons', url = 'https://github.com/nvim-tree/nvim-web-devicons.git' },
  { 'diffview.nvim', url = 'https://github.com/sindrets/diffview.nvim.git' },
  { 'folke/which-key.nvim', url = 'https://github.com/folke/which-key.nvim.git' },
}

for _, spec in ipairs(plugins) do
  local install_path = plugin_dir .. '/' .. spec[1]
  if vim.fn.isdirectory(install_path) ~= 1 then
    if spec.url then
      print(string.format("Installing '%s'...", spec[1]))
      vim.fn.system({ 'git', 'clone', '--depth=1', spec.url, install_path })
    end
  end
  vim.opt.runtimepath:append(spec.path or install_path)
end

local actions = require('diffview.actions')
require('diffview').setup({
  keymaps = {
    view = {
      { 'n', '<tab>', actions.select_next_entry, { desc = 'Next file diff' } },
      { 'n', '<s-tab>', actions.select_prev_entry, { desc = 'Previous file diff' } },
      { 'n', '[x', actions.prev_conflict, { desc = 'Previous conflict' } },
      { 'n', ']x', actions.next_conflict, { desc = 'Next conflict' } },
      { 'n', '<localleader>xo', actions.conflict_choose('ours'), { desc = 'Accept ours' } },
      { 'n', '<localleader>xt', actions.conflict_choose('theirs'), { desc = 'Accept theirs' } },
      { 'n', '<localleader>xb', actions.conflict_choose('base'), { desc = 'Accept base' } },
      { 'n', '<localleader>xa', actions.conflict_choose('all'), { desc = 'Accept all' } },
      { 'n', '<localleader>Xo', actions.conflict_choose_all('ours'), { desc = 'Accept ours (whole file)' } },
      { 'n', '<localleader>Xt', actions.conflict_choose_all('theirs'), { desc = 'Accept theirs (whole file)' } },
      { 'n', '<localleader>Xb', actions.conflict_choose_all('base'), { desc = 'Accept base (whole file)' } },
      { 'n', '<localleader>Xa', actions.conflict_choose_all('all'), { desc = 'Accept all (whole file)' } },
    },
  },
})

vim.g.mapleader = ' '
vim.g.maplocalleader = ','
vim.opt.termguicolors = true
vim.cmd('colorscheme ' .. (vim.fn.has('nvim-0.8') == 1 and 'habamax' or 'slate'))

print('Ready!')
@garlicbreadcleric garlicbreadcleric added the bug Something isn't working label Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant