lewis6991 / gitsigns.nvim

Git integration for buffers
MIT License
5.23k stars 191 forks source link

README has wrong visual mode keybindings instructions #462

Closed aleprovencio closed 2 years ago

aleprovencio commented 2 years ago

Description

The visual mode versions of stage_hunk and reset_hunk commands should have ranges as arguments, otherwise they won't work.

Neovim version

0.6.1

Operating system and version

Archlinux

Steps to reproduce

  1. nvim -nu minimal.lua
  2. visually select a range inside a hunk to stage
  3. use the configured keymap to stage

Expected behavior

Only the selected range should be staged

Actual behavior

Whole hunk is staged

Gitsigns debug messages

No response

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'

if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Gitsigns and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end

-- Load plugins
require('packer').startup {
  {
    'wbthomason/packer.nvim',
    {
      'lewis6991/gitsigns.nvim',
      requires = { 'nvim-lua/plenary.nvim' },
    },
    -- 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 },
  },
}

_G.load_config = function()
  require('gitsigns').setup{
    debug_mode = true, -- You must add this to enable debug messages
    -- GITSIGNS CONFIG THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
  }

  -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE

  -- ALSO INCLUDE GITSIGNS DEBUG MESSAGES
  vim.cmd('Gitsigns debug_messages')
end

require('packer').sync()

vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
aleprovencio commented 2 years ago

@lewis6991 is this code working for you?

On my side I had to do something like (for nvim 0.6):

  map('v', '<leader>hs', '<cmd>lua require"gitsigns".stage_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>')
  map('v', '<leader>hr', '<cmd>lua require"gitsigns".reset_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>')
lewis6991 commented 2 years ago

Yes, that appears to work for me.