Go to file
Lewis Russell ee454e1846 Improve highlight derivation
- Simplify code
- Search for more known highlight groups, e.g:
    - GitGutterAdd
    - SignifySignAdd
    - DiffAddedGutter
    - diffAdded
    - DiffAdd'
2021-06-26 14:22:13 +01:00
.github Update issue templates 2021-05-06 17:11:05 +01:00
doc Improve highlight derivation 2021-06-26 14:22:13 +01:00
lua Improve highlight derivation 2021-06-26 14:22:13 +01:00
teal Improve highlight derivation 2021-06-26 14:22:13 +01:00
test Improve highlight derivation 2021-06-26 14:22:13 +01:00
types Migrate to plenary async2 2021-06-21 15:25:48 +01:00
.editorconfig Add .editorconfig 2021-02-07 12:39:38 +00:00
.gitattributes Improve sign speculation 2021-04-16 17:08:19 +01:00
.gitignore Better handling of new files 2021-01-02 13:17:42 +00:00
.luacheckrc Fixup lint errors 2020-12-14 23:24:03 +00:00
CONTRIBUTING.md Add CONTRIBUTING.md 2021-06-06 23:21:42 +01:00
gen_async.lua Change style of requires from / to . 2021-04-25 16:52:12 +01:00
gen_help.lua feat: Add config.on_attach() 2021-05-30 16:35:14 +01:00
LICENSE Initial commit 2020-10-18 11:14:44 +01:00
Makefile Rework testsuite 2021-06-23 11:41:48 +01:00
README.md feat: Live word diff 2021-06-25 17:12:27 +01:00
tlconfig.lua Update to teal 0.13.1 2021-03-23 15:35:46 +00:00

gitsigns.nvim

CI Version License: MIT Gitter

Super fast git decorations implemented purely in lua/teal.

Preview

Hunk Actions Line Blame

Features

  • Signs for added, removed, and changed lines
  • Asynchronous using luv
  • Navigation between hunks
  • Stage hunks (with undo)
  • Preview diffs of hunks (with word diff)
  • Customisable (signs, highlights, mappings, etc)
  • Status bar integration
  • Git blame a specific line using virtual text.
  • Hunk text object
  • Automatically follow files moved in the index.
  • Live intra-line word diff
  • Support for yadm

Requirements

  • Neovim >= 0.5.0
  • Newish version of git. Older versions may not work with some features.

Installation

packer.nvim:

use {
  'lewis6991/gitsigns.nvim',
  requires = {
    'nvim-lua/plenary.nvim'
  }
}

vim-plug:

Plug 'nvim-lua/plenary.nvim'
Plug 'lewis6991/gitsigns.nvim'

Usage

For basic setup with all batteries included:

require('gitsigns').setup()

If using packer.nvim gitsigns can be setup directly in the plugin spec:

use {
  'lewis6991/gitsigns.nvim',
  requires = {
    'nvim-lua/plenary.nvim'
  },
  config = function()
    require('gitsigns').setup()
  end
}

Configuration can be passed to the setup function. Here is an example with most of the default settings:

require('gitsigns').setup {
  signs = {
    add          = {hl = 'GitSignsAdd'   , text = '│', numhl='GitSignsAddNr'   , linehl='GitSignsAddLn'},
    change       = {hl = 'GitSignsChange', text = '│', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'},
    delete       = {hl = 'GitSignsDelete', text = '_', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'},
    topdelete    = {hl = 'GitSignsDelete', text = '‾', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'},
    changedelete = {hl = 'GitSignsChange', text = '~', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'},
  },
  numhl = false,
  linehl = false,
  keymaps = {
    -- Default keymap options
    noremap = true,
    buffer = true,

    ['n ]c'] = { expr = true, "&diff ? ']c' : '<cmd>lua require\"gitsigns.actions\".next_hunk()<CR>'"},
    ['n [c'] = { expr = true, "&diff ? '[c' : '<cmd>lua require\"gitsigns.actions\".prev_hunk()<CR>'"},

    ['n <leader>hs'] = '<cmd>lua require"gitsigns".stage_hunk()<CR>',
    ['v <leader>hs'] = '<cmd>lua require"gitsigns".stage_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
    ['n <leader>hu'] = '<cmd>lua require"gitsigns".undo_stage_hunk()<CR>',
    ['n <leader>hr'] = '<cmd>lua require"gitsigns".reset_hunk()<CR>',
    ['v <leader>hr'] = '<cmd>lua require"gitsigns".reset_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
    ['n <leader>hR'] = '<cmd>lua require"gitsigns".reset_buffer()<CR>',
    ['n <leader>hp'] = '<cmd>lua require"gitsigns".preview_hunk()<CR>',
    ['n <leader>hb'] = '<cmd>lua require"gitsigns".blame_line(true)<CR>',

    -- Text objects
    ['o ih'] = ':<C-U>lua require"gitsigns.actions".select_hunk()<CR>',
    ['x ih'] = ':<C-U>lua require"gitsigns.actions".select_hunk()<CR>'
  },
  watch_index = {
    interval = 1000,
    follow_files = true
  },
  current_line_blame = false,
  current_line_blame_delay = 1000,
  current_line_blame_position = 'eol',
  sign_priority = 6,
  update_debounce = 100,
  status_formatter = nil, -- Use default
  word_diff = false,
  use_decoration_api = true,
  use_internal_diff = true,  -- If luajit is present
}

For information on configuring neovim via lua please see nvim-lua-guide.

Status Line

Use b:gitsigns_status or b:gitsigns_status_dict. b:gitsigns_status is formatted using config.status_formatter. b:gitsigns_status_dict is a dictionary with the keys added, removed, changed and head.

Example:

set statusline+=%{get(b:,'gitsigns_status','')}

For the current branch use the variable b:gitsigns_head.

TODO

  • Add ability to show staged hunks with different signs (maybe in a different sign column?)
  • Add ability to show commit in floating window of current line
  • Allow extra options to be passed to git diff
  • Folding of text around hunks
  • Diff against working tree instead of index, or diff against any SHA.
  • Open diff mode of buffer against what gitsigns is comparing to (currently the index)
  • Show messages when navigating hunks similar to '/' search

Similar plugins