All Projects → niklaas → lightline-gitdiff

niklaas / lightline-gitdiff

Licence: other
Show added, deleted and modified lines (`git diff`) in your statusline or lightline

Programming Languages

Vim Script
2826 projects
shell
77523 projects

Projects that are alternatives of or similar to lightline-gitdiff

Vim Gitgutter
A Vim plugin which shows git diff markers in the sign column and stages/previews/undoes hunks and partial hunks.
Stars: ✭ 7,364 (+27174.07%)
Mutual labels:  diff, gitgutter
unidiff-rs
Unified diff parsing/metadata extraction library for Rust
Stars: ✭ 19 (-29.63%)
Mutual labels:  diff, git-diff
go-delta
go-delta - A Go package and utility to generate and apply binary delta updates.
Stars: ✭ 25 (-7.41%)
Mutual labels:  diff
textdiff-create
Create lean text diff deltas.
Stars: ✭ 25 (-7.41%)
Mutual labels:  diff
Diff.Net
A differencing utility for Window desktop written in C#.
Stars: ✭ 34 (+25.93%)
Mutual labels:  diff
langx-java
Java tools, helper, common utilities. A replacement of guava, apache-commons, hutool
Stars: ✭ 50 (+85.19%)
Mutual labels:  diff
diffhtml
Tools for generating diff output in HTML.
Stars: ✭ 23 (-14.81%)
Mutual labels:  diff
gonp
diff algorithm in Go
Stars: ✭ 42 (+55.56%)
Mutual labels:  diff
quantum.vim
A colorscheme based on the Firefox DevTools
Stars: ✭ 46 (+70.37%)
Mutual labels:  lightline
diff-text
Just get the diff of a simple inline text, simple mode.
Stars: ✭ 13 (-51.85%)
Mutual labels:  diff
gitdub
📤 A github WebHook that emails detailed diffs of your commits.
Stars: ✭ 25 (-7.41%)
Mutual labels:  diff
dipa
dipa makes it easy to efficiently delta encode large Rust data structures.
Stars: ✭ 243 (+800%)
Mutual labels:  diff
intellij-diff-plugin
Syntax highlighting for .diff files and .patch files in IntelliJ IDEs
Stars: ✭ 17 (-37.04%)
Mutual labels:  diff
fdiff
An OpenType table diff tool for fonts. Based on the fontTools TTX format.
Stars: ✭ 33 (+22.22%)
Mutual labels:  diff
extract-html-diff
extract difference between two html pages
Stars: ✭ 29 (+7.41%)
Mutual labels:  diff
vim-lighthaus
A Lighthaus theme for (n)vim, vim-airline and lightline
Stars: ✭ 33 (+22.22%)
Mutual labels:  lightline
nano-staged
Tiny tool to run commands for modified, staged, and committed files in a GIT repository.
Stars: ✭ 347 (+1185.19%)
Mutual labels:  diff
dify
A fast pixel-by-pixel image comparison tool in Rust
Stars: ✭ 41 (+51.85%)
Mutual labels:  diff
fast diff match patch
Python package for Google's diff-match-patch native C++ implementation.
Stars: ✭ 55 (+103.7%)
Mutual labels:  diff
dif
'dif' is a Linux preprocessing front end to gvimdiff/meld/kompare
Stars: ✭ 18 (-33.33%)
Mutual labels:  diff

lightline-gitdiff

I had been using airblade/vim-gitgutter for a while, however, I felt distracted by the indicators shown in the sign column in the end. That said, I wanted some lightweight signal indicating whether the current file contains uncommitted changes to the repository or not.

So, this little plugin was born. I myself use itchyny/lightline.vim to configure the statusline of vim easily, so this is where the name of the plugin comes from. In addition, I embrace lightlines's philosophy to provide a lightweight and stable, yet configurable plugin that "just works". However, you can also integrate the plugin with vim's vanilla statusline.

By default the plugin shows indicators such as the following:

A: 4 D: 6 M: 2

This says that, in comparison to the git index, the current buffer contains 12 uncommitted changes: four lines were deleted, six lines were added and two lines only modified. If there are no uncommitted changes, nothing is shown to reduce distraction.

You can see the plugin in action in my statusline/lightline:

screenshot

Installation

Use your favorite plugin manager to install the plugin. I personally prefer vim-plug but feel free to choose another one:

Plug 'niklaas/lightline-gitdiff'

Configuration

Using vim's vanilla statusline

set statusline=%!lightline#gitdiff#get()

which let's your statusline consist of gitdiff's indicators only. (Probably not what you want but you can consult :h statusline for further information on how to include additional elements.)

Using lightline

let g:lightline = {
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ],
      \             [ 'gitbranch', 'filename', 'readonly', 'modified' ],
      \             [ 'gitdiff' ] ],
      \   'right': [ [ 'lineinfo' ],
      \              [ 'percent' ] ]
      \ },
      \ 'inactive': {
      \   'left': [ [ 'filename', 'gitversion' ] ],
      \ },
      \ 'component_function': {
      \   'gitbranch': 'fugitive#head',
      \ },
      \ 'component_expand': {
      \   'gitdiff': 'lightline#gitdiff#get',
      \ },
      \ 'component_type': {
      \   'gitdiff': 'middle',
      \ },
      \ }

which should give you pretty much the same result as shown in the screenshot.

Configuration

You can configure the appearance of the indicators and the separator between them. The following are the defaults:

let g:lightline#gitdiff#indicator_added = 'A: '
let g:lightline#gitdiff#indicator_deleted = 'D: '
let g:lightline#gitdiff#separator = ' '

A callback function is called every time the diff is updated and written to the cache. By default this is lightline#update() to update lightline with the newly calculated diff. However, you can also provide you own callback function in the following way:

let g:lightline#gitdiff#update_callback = { -> MyCustomCallback() }

If the callback function is not defined, the error is caught. This allows to use the plugin with any type of statusline plugin.

You can even change the algorithm that is used to calculate the diff. The plugin comes bundled with two algorithms: numstat and word_diff_porcelain. By default, the latter one is used because it allows to display modified lines. numstat is much simpler but only supports showing added and deleted lines. This resembles the default:

let g:LightlineGitDiffAlgorithm =
      \ { buffer -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate(buffer) }

Substitute word_diff_porcelain with numstat if you want to switch -- or provide your own. Take a look at the source of both functions for inspiration or consult me if you need help. I am happy to bundle additional faster and more feature-rich algorithms in the package.

You can show empty indicators (i.e. A: 0 D: 0 M: 0) in the following way:

let g:lightline#gitdiff#show_empty_indicators = 1

How it works / performance

In the background, lightline#gitdiff#get() calls git --numstat or git --word-diff=porcelain (depending on the algorithm you choose, the latter being the default) for the current buffer and caches the result.

If possible e.g., when an already open buffer is entered, the cache is used and no call to git is made. git is only executed when reading or writing to a buffer. See the augroup in plugin/lightline/gitdiff.vim.

If you have any suggestions to improve the performance, please let me know. I am happy to implement your suggestions on my own -- or you can create a pull request.

Bugs etc.

Probably this code has some sharp edges. Feel free to report bugs, suggestions and pull requests. I'll try to fix them as soon as possible.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].