diff --git a/README.mkd b/README.mkd index bf0d4bf..ff53b60 100644 --- a/README.mkd +++ b/README.mkd @@ -55,18 +55,30 @@ You don't have to do anything: it just works. With one exception the plugin diffs your saved buffers, i.e. the files on disk. It produces the same result as running `git diff` on the command line. The exception is realtime updating: in this case the plugin diffs the (unsaved) buffer contents against the version in git. + +#### Activation + You can explicitly turn vim-gitgutter off and on (defaults to on): * turn off with `:GitGutterDisable` * turn on with `:GitGutterEnable` * toggle with `:GitGutterToggle`. +You can turn the signs on and off (defaults to on): + +* turn on with `:GitGutterSignsEnable` +* turn off with `:GitGutterSignsDisable` +* toggle with `:GitGutterSignsToggle`. + And you can turn line highlighting on and off (defaults to off): * turn on with `:GitGutterLineHighlightsEnable` * turn off with `:GitGutterLineHighlightsDisable` * toggle with `:GitGutterLineHighlightsToggle`. + +#### Hunks + Furthermore you can jump between hunks: * jump to next hunk (change): `]c` @@ -177,13 +189,6 @@ let g:gitgutter_sign_removed = 'zz' let g:gitgutter_sign_modified_removed = 'ww' ``` -#### Whether or not signs are shown - -If you never want signs to be shown (presumably you only want the line highlights), add this to your `~/.vimrc`: - -```viml -let g:gitgutter_signs = 0 -``` #### Line highlights @@ -228,6 +233,11 @@ let g:gitgutter_escape_grep = 1 Add `let g:gitgutter_enabled = 0` to your `~/.vimrc`. +#### To turn off signs by default + +Add `let g:gitgutter_signs = 0` to your `~/.vimrc`. + + #### To turn on line highlighting by default Add `let g:gitgutter_highlight_lines = 1` to your `~/.vimrc`. diff --git a/autoload/highlight.vim b/autoload/highlight.vim index 682fbcd..fa909e3 100644 --- a/autoload/highlight.vim +++ b/autoload/highlight.vim @@ -28,10 +28,8 @@ function! highlight#define_signs() sign define GitGutterLineModifiedRemoved sign define GitGutterDummy - if g:gitgutter_signs - call highlight#define_sign_symbols() - call highlight#define_sign_text_highlights() - endif + call highlight#define_sign_symbols() + call highlight#define_sign_text_highlights() call highlight#define_sign_line_highlights() endfunction diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index c7ed528..fc3938d 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -67,6 +67,17 @@ Commands for turning Git Gutter on and off: :GitGutterAll *:GitGutterAll* Update signs across all buffers. +Commands for turning signs on and off (defaults to on): + + :GitGutterSignsEnable *:GitGutterSignsEnable* + Explicitly turn line signs on. + + :GitGutterSignsDisable *:GitGutterSignsDisable* + Explicitly turn line signs off. + + :GitGutterSignsToggle *:GitGutterSignsToggle* + Explicitly turn line signs on if it was off and vice versa. + Commands for turning line highlighting on and off (defaults to off): :GitGutterLineHighlightsEnable *:GitGutterLineHighlightsEnable* @@ -165,13 +176,6 @@ To customise the symbols, add the following to your |vimrc|: let g:gitgutter_sign_modified_removed = 'ww' < -SIGNS - -To never show signs, use this: -> - let g:gitgutter_signs = 0 -< - LINE HIGHLIGHTS Similarly to the signs' colours, set up the following highlight groups in your @@ -223,6 +227,13 @@ Add to your |vimrc| let g:gitgutter_enabled = 0 < +TO TURN OFF SIGNS BY DEFAULT + +Add to your |vimrc| +> + let g:gitgutter_signs = 0 +< + TO TURN ON LINE HIGHLIGHTING BY DEFAULT Add to your |vimrc| diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index da33a4b..68321b4 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -60,16 +60,18 @@ function! GitGutter(file, realtime) let s:hunks = diff#parse_diff(diff) let modified_lines = diff#process_hunks(s:hunks) - if g:gitgutter_sign_column_always - call sign#add_dummy_sign() - else - if utility#differences(s:hunks) - call sign#add_dummy_sign() " prevent flicker + if g:gitgutter_signs + if g:gitgutter_sign_column_always + call sign#add_dummy_sign() else - call sign#remove_dummy_sign() + if utility#differences(s:hunks) + call sign#add_dummy_sign() " prevent flicker + else + call sign#remove_dummy_sign() + endif endif + call sign#update_signs(a:file, modified_lines) endif - call sign#update_signs(a:file, modified_lines) call utility#save_last_seen_change(a:file) endif @@ -133,6 +135,38 @@ function! GitGutterNextHunk(count) if hunk_count == a:count execute 'normal!' hunk[2] . 'G' break +" }}} + + +" Signs: enable / disable / toggle {{{ + +function! GitGutterSignsEnable() + let g:gitgutter_signs = 1 + call GitGutterAll() +endfunction +command GitGutterSignsEnable call GitGutterSignsEnable() + +function! GitGutterSignsDisable() + let g:gitgutter_signs = 0 + call sign#clear_signs(utility#file()) + call sign#remove_dummy_sign() +endfunction +command GitGutterSignsDisable call GitGutterSignsDisable() + +function! GitGutterSignsToggle() + if g:gitgutter_signs + call GitGutterSignsDisable() + else + call GitGutterSignsEnable() + endif +endfunction +command GitGutterSignsToggle call GitGutterSignsToggle() + +" }}} + + +" Hunks: jump to next/previous {{{ + endif endif endfor