diff --git a/README.mkd b/README.mkd index e9f98a1..78fbaf6 100644 --- a/README.mkd +++ b/README.mkd @@ -204,6 +204,7 @@ To customise the symbols, add the following to your `~/.vimrc`: let g:gitgutter_sign_added = 'xx' let g:gitgutter_sign_modified = 'yy' let g:gitgutter_sign_removed = 'zz' +let g:gitgutter_sign_removed_first_line = '^^' let g:gitgutter_sign_modified_removed = 'ww' ``` @@ -276,10 +277,6 @@ let g:gitgutter_realtime = 0 let g:gitgutter_eager = 0 ``` -> Why is no sign shown if I delete the first line(s) in a file? - -vim-gitgutter shows removed lines with a sign on the line above. In this case there isn't a line above so vim-gitgutter can't show the sign. In due course I'll fix this with an overline character on the first line. - > What happens if I also use another plugin which uses signs (e.g. Syntastic)? Vim only allows one sign per line. Before adding a sign to a line, vim-gitgutter checks whether a sign has already been added by somebody else. If so it doesn't do anything. In other words vim-gitgutter won't overwrite another plugin's signs. It also won't remove another plugin's signs. diff --git a/autoload/diff.vim b/autoload/diff.vim index 16081b1..b4af17c 100644 --- a/autoload/diff.vim +++ b/autoload/diff.vim @@ -142,7 +142,11 @@ function! diff#process_added(modifications, from_count, to_count, to_line) endfunction function! diff#process_removed(modifications, from_count, to_count, to_line) - call add(a:modifications, [a:to_line, 'removed']) + if a:to_line == 0 + call add(a:modifications, [1, 'removed_first_line']) + else + call add(a:modifications, [a:to_line, 'removed']) + endif endfunction function! diff#process_modified(modifications, from_count, to_count, to_line) diff --git a/autoload/highlight.vim b/autoload/highlight.vim index 0b36e64..1ad1f33 100644 --- a/autoload/highlight.vim +++ b/autoload/highlight.vim @@ -34,6 +34,7 @@ function! highlight#define_signs() sign define GitGutterLineAdded sign define GitGutterLineModified sign define GitGutterLineRemoved + sign define GitGutterLineRemovedFirstLine sign define GitGutterLineModifiedRemoved sign define GitGutterDummy @@ -46,6 +47,7 @@ function! highlight#define_sign_text() execute "sign define GitGutterLineAdded text=" . g:gitgutter_sign_added execute "sign define GitGutterLineModified text=" . g:gitgutter_sign_modified execute "sign define GitGutterLineRemoved text=" . g:gitgutter_sign_removed + execute "sign define GitGutterLineRemovedFirstLine text=" . g:gitgutter_sign_removed_first_line execute "sign define GitGutterLineModifiedRemoved text=" . g:gitgutter_sign_modified_removed endfunction @@ -68,6 +70,7 @@ function! highlight#define_sign_text_highlights() sign define GitGutterLineAdded texthl=GitGutterAdd sign define GitGutterLineModified texthl=GitGutterChange sign define GitGutterLineRemoved texthl=GitGutterDelete + sign define GitGutterLineRemovedFirstLine texthl=GitGutterDelete sign define GitGutterLineModifiedRemoved texthl=GitGutterChangeDelete endfunction @@ -76,11 +79,13 @@ function! highlight#define_sign_line_highlights() sign define GitGutterLineAdded linehl=GitGutterAddLine sign define GitGutterLineModified linehl=GitGutterChangeLine sign define GitGutterLineRemoved linehl=GitGutterDeleteLine + sign define GitGutterLineRemovedFirstLine linehl=GitGutterDeleteLine sign define GitGutterLineModifiedRemoved linehl=GitGutterChangeDeleteLine else sign define GitGutterLineAdded linehl= sign define GitGutterLineModified linehl= sign define GitGutterLineRemoved linehl= + sign define GitGutterLineRemovedFirstLine linehl= sign define GitGutterLineModifiedRemoved linehl= endif endfunction diff --git a/autoload/hunk.vim b/autoload/hunk.vim index e8e9c0d..ee6655d 100644 --- a/autoload/hunk.vim +++ b/autoload/hunk.vim @@ -54,7 +54,8 @@ function! hunk#prev_hunk(count) if hunk[2] < current_line let hunk_count += 1 if hunk_count == a:count - execute 'normal!' hunk[2] . 'G' + let target = hunk[2] == 0 ? 1 : hunk[2] + execute 'normal!' target . 'G' break endif endif @@ -69,6 +70,11 @@ function! hunk#current_hunk() let current_line = line('.') for hunk in s:hunks + if current_line == 1 && hunk[2] == 0 + let current_hunk = hunk + break + endif + if current_line >= hunk[2] && current_line < hunk[2] + (hunk[3] == 0 ? 1 : hunk[3]) let current_hunk = hunk break diff --git a/autoload/utility.vim b/autoload/utility.vim index 43e7149..59a7483 100644 --- a/autoload/utility.vim +++ b/autoload/utility.vim @@ -88,6 +88,8 @@ function! utility#highlight_name_for_change(text) return 'GitGutterLineAdded' elseif a:text ==# 'removed' return 'GitGutterLineRemoved' + elseif a:text ==# 'removed_first_line' + return 'GitGutterLineRemovedFirstLine' elseif a:text ==# 'modified' return 'GitGutterLineModified' elseif a:text ==# 'modified_removed' diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index f69eb29..62bdba2 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -270,12 +270,7 @@ a. Why are the colours in the sign column weird? Your colorscheme is configuring the |hl-SignColumn| highlight group weirdly. Please see |GitGutterCustomisation| on customising the sign column. -b. Why is no sign shown if I delete the first line(s) in a file? - - vim-gitgutter shows removed lines with a sign on the line above. In this - case there isn't a line above so vim-gitgutter can't show the sign. - -c. What happens if I also use another plugin which uses signs (e.g. Syntastic)? +b. What happens if I also use another plugin which uses signs (e.g. Syntastic)? Vim only allows one sign per line. Before adding a sign to a line, vim-gitgutter checks whether a sign has already been added by somebody else. diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index 41d6f6e..65e121b 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -34,6 +34,7 @@ call s:set('g:gitgutter_eager', 1) call s:set('g:gitgutter_sign_added', '+') call s:set('g:gitgutter_sign_modified', '~') call s:set('g:gitgutter_sign_removed', '_') +call s:set('g:gitgutter_sign_removed_first_line', '‾') call s:set('g:gitgutter_sign_modified_removed', '~_') call s:set('g:gitgutter_diff_args', '') call s:set('g:gitgutter_escape_grep', 0)