Skip to content

Defining on_attach inverts git navigation ]c and [c #1514

Closed
@cptchuckles

Description

@cptchuckles

Description

:help nvim-tree-default-mappings indicates:

    { key = "[c",                             action = "prev_git_item" },
    { key = "]c",                             action = "next_git_item" },

but as soon as you define on_attach, they are backwards. Pressing [c goes to the next git item, and ]c goes to the previous item.
I had to fix these in my config:

require('nvim-tree').setup {
	remove_keymaps = {
		'[c', ']c',  -- Default git prev/next
	},

	on_attach = function(bufnr)
		local ntapi = require('nvim-tree.api')
		local map = function(m, lhs, rhs)
			vim.keymap.set(m, lhs, rhs, { buffer = bufnr, remap = false })
		end
		map('n', '[c', ntapi.node.navigate.git.prev)
		map('n', ']c', ntapi.node.navigate.git.next)
	end,
}

Neovim version

NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

Linux x1e2 5.18.16-artix1-1 #1 SMP PREEMPT_DYNAMIC Wed, 03 Aug 2022 13:26:46 +0000 x86_64 GNU/Linux

nvim-tree version

09a5126

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvt-min/site]]
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup {
    {
      "wbthomason/packer.nvim",
      "kyazdani42/nvim-tree.lua",
      "kyazdani42/nvim-web-devicons",
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  }
end
if vim.fn.isdirectory(install_path) == 0 then
  print "Installing nvim-tree and dependencies."
  vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
end
load_plugins()
require("packer").sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup {
	  on_attach = function(bufnr)
	  end,
  }
end

Steps to reproduce

  1. nvim -nu /tmp/nvt-min.lua
  2. :NvimTreeOpen
  3. find somewhere with git diffs
  4. navigate them with [c and ]c

Expected behavior

]c goes next, [c goes previous

Actual behavior

the opposite

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions