sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
4.04k stars 112 forks source link

Keybindings are not working for me #62

Closed Dante-666 closed 3 years ago

Dante-666 commented 3 years ago

Hi,

I've setup the plugin according to the docs but some keybindings are not working for me. It could be that I am understanding the plugin incorrectly

I can use and focus_files and toggle_files but when I press j and k in the right_panel, it moves just one line ahead like in normal mode instead of to the next diff.

Also is the X key supposed to revert the state back to original? That's also not working for me.

Please let me know what I may be doing wrong here.

return require('packer').startup(function()
  -- Packer can manage itself
  use 'wbthomason/packer.nvim'

  -- tpope
  use 'tpope/vim-surround'
  use 'tpope/vim-fugitive'
  -- git
  use { 'lewis6991/gitsigns.nvim',
      requires = {
          'nvim-lua/plenary.nvim'
      }
  }
  use 'sindrets/diffview.nvim'
  -- colors
  use 'norcalli/nvim-colorizer.lua'
  -- File explorer
  use 'kyazdani42/nvim-web-devicons'
  use 'kyazdani42/nvim-tree.lua'
  -- lsp
  use 'neovim/nvim-lspconfig'
  use 'glepnir/lspsaga.nvim'
  use {'folke/trouble.nvim',
    requires = 'kyazdani42/nvim-web-devicons'
  }
  -- formatter
  use 'sbdchd/neoformat'
  -- autocomplete
  use 'hrsh7th/nvim-compe'
  use 'hrsh7th/vim-vsnip'
  use 'rafamadriz/friendly-snippets'
  -- file and string search
  use {'nvim-telescope/telescope.nvim',
    requires = { 
            'nvim-lua/popup.nvim', 
            'nvim-lua/plenary.nvim'
        }
  }
  use 'nvim-telescope/telescope-fzy-native.nvim'
  use 'nvim-telescope/telescope-project.nvim'

  -- syntax highlights
  use 'Yagua/nebulous.nvim'
  use {'nvim-treesitter/nvim-treesitter', run = ":TSUpdate"}
  use 'andymass/vim-matchup'
  -- comments
  use 'terrortylor/nvim-comment'
  use 'JoosepAlviste/nvim-ts-context-commentstring'
  -- status and buffer line
  use 'glepnir/galaxyline.nvim'
    use 'akinsho/nvim-bufferline.lua'
    -- debugger
    use 'sakhnik/nvim-gdb'

end)
require'nvim_comment'.setup()

require'nvim-treesitter.configs'.setup {
    ensure_installed = O.treesitter.ensure_installed, -- one of "all", "maintained" (parsers with maintainers), or a list of languages
    ignore_install = O.treesitter.ignore_install,
    matchup = {
        enable = true,              -- mandatory, false will disable the whole extension
        -- disable = { "c", "ruby" },  -- optional, list of language that will be disabled
    },
    highlight = {
        enable = O.treesitter.highlight.enabled -- false will disable the whole extension
    },
    context_commentstring = {
        enable = true,
        config = {
          css = '// %s'
        }
      },
    -- indent = {enable = true, disable = {"python", "html", "javascript"}},
    --indent = {enable = true},
    autotag = {enable = true},
}

require("nebulous").setup()

require('gitsigns').setup()

local cb = require'diffview.config'.diffview_callback

require'diffview'.setup {
  diff_binaries = false,    -- Show diffs for binaries
  file_panel = {
    width = 35,
    use_icons = true        -- Requires nvim-web-devicons
  },
  key_bindings = {
    disable_defaults = false,                   -- Disable the default key bindings
    -- The `view` bindings are active in the diff buffers, only when the current
    -- tabpage is a Diffview.
    view = {
      ["<tab>"]     = cb("select_next_entry"),  -- Open the diff for the next file 
      ["<s-tab>"]   = cb("select_prev_entry"),  -- Open the diff for the previous file
      ["<leader>e"] = cb("focus_files"),        -- Bring focus to the files panel
      ["<leader>b"] = cb("toggle_files"),       -- Toggle the files panel.
    },
    file_panel = {
      ["j"]             = cb("next_entry"),         -- Bring the cursor to the next file entry
      ["<down>"]        = cb("next_entry"),
      ["k"]             = cb("prev_entry"),         -- Bring the cursor to the previous file entry.
      ["<up>"]          = cb("prev_entry"),
      ["<cr>"]          = cb("select_entry"),       -- Open the diff for the selected entry.
      ["o"]             = cb("select_entry"),
      ["<2-LeftMouse>"] = cb("select_entry"),
      ["-"]             = cb("toggle_stage_entry"), -- Stage / unstage the selected entry.
      ["S"]             = cb("stage_all"),          -- Stage all entries.
      ["U"]             = cb("unstage_all"),        -- Unstage all entries.
      ["X"]             = cb("restore_entry"),      -- Restore entry to the state on the left side.
      ["R"]             = cb("refresh_files"),      -- Update stats and entries in the file list.
      ["<tab>"]         = cb("select_next_entry"),
      ["<s-tab>"]       = cb("select_prev_entry"),
      ["<leader>e"]     = cb("focus_files"),
      ["<leader>b"]     = cb("toggle_files"),
    }
  }
}
sindrets commented 3 years ago

You seem to be a little confused about how the bindings work. As described in the README, and the docs: the mappings are separated into different contexts. Namely the view context, and the file panel context. Bindings added to the view table will only work from the diff buffers. Bindings added to the file_panel table will only work in the file panel. You can add, remove or move any bindings between these two tables to get your desired config. Most of the operations work from both the view and the file panel (when the mappings are added), except for a few. This is described in detail in the docs.

You also seem to be confused about what the next_entry and prev_entry operations do. These are the only strictly "file-panel-only" operations. As in, they only work correctly from the file panel. Thus, these operations are not for bringing the cursor to the next diff hunk, but rather for bringing the cursor to the next file entry in the file panel (it's just to make it more UI-like: limiting the cursor from moving to text decorations, and titles and such. It will skip over the text like "Staged Changes" and move straight to the next file entry. If you don't like it you can just remove the bindings).

Vim already has mappings for moving between diff hunks by default: c[ and c]. Please see :h jumpto-diffs.

Also is the X key supposed to revert the state back to original? That's also not working for me.

Yes, that is what it does. But again: by default it's only added to the file panel bindings, and thus cannot be invoked from the diff buffers. You can of course add it to the view bindings. It works perfectly fine from the diff buffers (again; as long as the mappings are added).

Dante-666 commented 3 years ago

Thanks a lot for the explanation. I have recently started using neovim(switched from vim and I am no expert vim user) and it can be a bit overwhelming. I'm trying things out and developing a workflow.