Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Features:
* Allows folding all unchanged text.
* Handles line endings correctly, even with repos that do CRLF conversion.
* Optional line highlighting.
* Fully customisable (signs, sign column, line highlights, mappings, extra git-diff arguments, etc).
* Optional line number highlighting. (Only available in Neovim 0.3.2 or higher)
* Fully customisable (signs, sign column, line (number) highlights, mappings, extra git-diff arguments, etc).
* Can be toggled on/off, globally or per buffer.
* Preserves signs from other plugins.
* Easy to integrate diff stats into status line; built-in integration with [vim-airline](https://github.com/bling/vim-airline/).
Expand Down Expand Up @@ -138,6 +139,12 @@ And you can turn line highlighting on and off (defaults to off):
* turn off with `:GitGutterLineHighlightsDisable`
* toggle with `:GitGutterLineHighlightsToggle`.

With Neovim 0.3.2 or higher, you can turn line number highlighting on and off (defaults to off):

* turn on with `:GitGutterLineNrHighlightsEnable`
* turn off with `:GitGutterLineNrHighlightsDisable`
* toggle with `:GitGutterLineNrHighlightsToggle`.

Note that if you have line highlighting on and signs off, you will have an empty sign column – more accurately, a sign column with invisible signs. This is because line highlighting requires signs and Vim always shows the sign column even if the signs are invisible.

If you switch off both line highlighting and signs, you won't see the sign column. That is unless you configure the sign column always to be there (see Sign Column section).
Expand Down Expand Up @@ -233,6 +240,7 @@ You can customise:
* Whether or not vim-gitgutter is on initially (defaults to on)
* Whether or not signs are shown (defaults to yes)
* Whether or not line highlighting is on initially (defaults to off)
* Whether or not line number highlighting is on initially (defaults to off)
* Whether or not vim-gitgutter runs in "realtime" (defaults to yes)
* Whether or not vim-gitgutter runs eagerly (defaults to yes)
* Whether or not vim-gitgutter runs asynchronously (defaults to yes)
Expand Down Expand Up @@ -324,6 +332,26 @@ highlight link GitGutterChangeLine DiffText
```


#### Line number highlights

NOTE: This feature requires Neovim 0.3.2 or higher.

Similarly to the signs' colours, set up the following highlight groups in your colorscheme or `~/.vimrc`:

```viml
GitGutterAddLineNr " default: links to CursorLineNr
GitGutterChangeLineNr " default: links to CursorLineNr
GitGutterDeleteLineNr " default: links to CursorLineNr
GitGutterChangeDeleteLineNr " default: links to CursorLineNr
```

Maybe you think `CursorLineNr` is a bit annoying. For example, you could use `Underlined` for this:

```viml
highlight link GitGutterChangeLineNr Underlined
```


#### The base of the diff

By default buffers are diffed against the index. However you can diff against any commit by setting:
Expand Down Expand Up @@ -384,6 +412,11 @@ Add `let g:gitgutter_signs = 0` to your `~/.vimrc`.
Add `let g:gitgutter_highlight_lines = 1` to your `~/.vimrc`.


#### To turn on line number highlighting by default

Add `let g:gitgutter_highlight_linenrs = 1` to your `~/.vimrc`.


#### To turn off asynchronous updates

By default diffs are run asynchronously. To run diffs synchronously instead:
Expand Down
59 changes: 59 additions & 0 deletions autoload/gitgutter/highlight.vim
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,39 @@ function! gitgutter#highlight#line_toggle() abort
endif
endfunction

function! gitgutter#highlight#linenr_disable() abort
let g:gitgutter_highlight_linenrs = 0
call s:define_sign_linenr_highlights()

if !g:gitgutter_signs
call gitgutter#sign#clear_signs(bufnr(''))
call gitgutter#sign#remove_dummy_sign(bufnr(''), 0)
endif

redraw!
endfunction

function! gitgutter#highlight#linenr_enable() abort
let old_highlight_lines = g:gitgutter_highlight_linenrs

let g:gitgutter_highlight_linenrs = 1
call s:define_sign_linenr_highlights()

if !old_highlight_lines && !g:gitgutter_signs
call gitgutter#all(1)
endif

redraw!
endfunction

function! gitgutter#highlight#linenr_toggle() abort
if g:gitgutter_highlight_linenrs
call gitgutter#highlight#linenr_disable()
else
call gitgutter#highlight#linenr_enable()
endif
endfunction


function! gitgutter#highlight#define_sign_column_highlight() abort
if g:gitgutter_override_sign_column_highlight
Expand Down Expand Up @@ -66,6 +99,11 @@ function! gitgutter#highlight#define_highlights() abort
highlight default link GitGutterChangeLine DiffChange
highlight default link GitGutterDeleteLine DiffDelete
highlight default link GitGutterChangeDeleteLine GitGutterChangeLine

highlight default link GitGutterAddLineNr CursorLineNr
highlight default link GitGutterChangeLineNr CursorLineNr
highlight default link GitGutterDeleteLineNr CursorLineNr
highlight default link GitGutterChangeDeleteLineNr CursorLineNr
endfunction

function! gitgutter#highlight#define_signs() abort
Expand All @@ -80,6 +118,7 @@ function! gitgutter#highlight#define_signs() abort
call s:define_sign_text()
call gitgutter#highlight#define_sign_text_highlights()
call s:define_sign_line_highlights()
call s:define_sign_linenr_highlights()
endfunction

function! s:define_sign_text() abort
Expand Down Expand Up @@ -131,6 +170,26 @@ function! s:define_sign_line_highlights() abort
endif
endfunction

function! s:define_sign_linenr_highlights() abort
if has('nvim-0.3.2')
if g:gitgutter_highlight_linenrs
sign define GitGutterLineAdded numhl=GitGutterAddLineNr
sign define GitGutterLineModified numhl=GitGutterChangeLineNr
sign define GitGutterLineRemoved numhl=GitGutterDeleteLineNr
sign define GitGutterLineRemovedFirstLine numhl=GitGutterDeleteLineNr
sign define GitGutterLineRemovedAboveAndBelow numhl=GitGutterDeleteLineNr
sign define GitGutterLineModifiedRemoved numhl=GitGutterChangeDeleteLineNr
else
sign define GitGutterLineAdded numhl=
sign define GitGutterLineModified numhl=
sign define GitGutterLineRemoved numhl=
sign define GitGutterLineRemovedFirstLine numhl=
sign define GitGutterLineRemovedAboveAndBelow numhl=
sign define GitGutterLineModifiedRemoved numhl=
endif
endif
endfunction

function! s:get_hl(group, what, mode) abort
let r = synIDattr(synIDtrans(hlID(a:group)), a:what, a:mode)
if empty(r) || r == -1
Expand Down
33 changes: 32 additions & 1 deletion doc/gitgutter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ Commands for turning line highlighting on and off (defaults to off):~
:GitGutterLineHighlightsToggle Turn line highlighting on or off.


Commands for turning line number highlighting on and off (defaults to off):~
NOTE: This feature requires Neovim 0.3.2 or higher.

*gitgutter-:GitGutterLineNrHighlightsEnable*
:GitGutterLineNrHighlightsEnable Turn on line highlighting.

*gitgutter-:GitGutterLineNrHighlightsDisable*
:GitGutterLineNrHighlightsDisable Turn off line highlighting.

*gitgutter-:GitGutterLineNrHighlightsToggle*
:GitGutterLineNrHighlightsToggle Turn line highlighting on or off.


Commands for jumping between hunks:~

*gitgutter-:GitGutterNextHunk*
Expand Down Expand Up @@ -249,6 +262,7 @@ Signs:~

|g:gitgutter_signs|
|g:gitgutter_highlight_lines|
|g:gitgutter_highlight_linenrs|
|g:gitgutter_max_signs|
|g:gitgutter_sign_added|
|g:gitgutter_sign_modified|
Expand Down Expand Up @@ -329,6 +343,11 @@ Default: 0

Determines whether or not to show line highlights.

*g:gitgutter_highlight_linenrs*
Default: 0

Determines whether or not to show line number highlights.

*g:gitgutter_max_signs*
Default: 500

Expand Down Expand Up @@ -457,7 +476,19 @@ colorscheme or |vimrc|:

For example, to use |hl-DiffText| instead of |hl-DiffChange|:
>
highlight link GitGutterChangeLine DiffChange
highlight link GitGutterChangeLine DiffText
<
To change the line number highlights, set up the following highlight groups in
your colorscheme or |vimrc|:
>
GitGutterAddLineNr " default: links to CursorLineNr
GitGutterChangeLineNr " default: links to CursorLineNr
GitGutterDeleteLineNr " default: links to CursorLineNr
GitGutterChangeDeleteLineNr " default: links to CursorLineNr
<
For example, to use |hl-Underlined| instead of |hl-CursorLineNr|:
>
highlight link GitGutterChangeLineNr Underlined
<


Expand Down
7 changes: 7 additions & 0 deletions plugin/gitgutter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ call s:set('g:gitgutter_enabled', 1)
call s:set('g:gitgutter_max_signs', 500)
call s:set('g:gitgutter_signs', 1)
call s:set('g:gitgutter_highlight_lines', 0)
call s:set('g:gitgutter_highlight_linenrs', 0)
call s:set('g:gitgutter_sign_column_always', 0)
if g:gitgutter_sign_column_always && exists('&signcolumn')
" Vim 7.4.2201.
Expand Down Expand Up @@ -111,6 +112,12 @@ command! -bar GitGutterLineHighlightsToggle call gitgutter#highlight#line_toggl

" }}}

" 'number' column highlights {{{
command! -bar GitGutterLineNrHighlightsDisable call gitgutter#highlight#linenr_disable()
command! -bar GitGutterLineNrHighlightsEnable call gitgutter#highlight#linenr_enable()
command! -bar GitGutterLineNrHighlightsToggle call gitgutter#highlight#linenr_toggle()
" }}}

" Signs {{{

command! -bar GitGutterSignsEnable call gitgutter#sign#enable()
Expand Down