mirror of
https://github.com/amix/vimrc
synced 2025-07-06 16:05:01 +08:00
Merge remote-tracking branch 'refs/remotes/upstream/master'
Conflicts: sources_non_forked/ale/autoload/ale.vim sources_non_forked/lightline.vim/doc/lightline.txt sources_non_forked/nerdtree/.github/PULL_REQUEST_TEMPLATE.md sources_non_forked/nerdtree/autoload/nerdtree.vim sources_non_forked/nerdtree/plugin/NERD_tree.vim sources_non_forked/vim-fugitive/autoload/fugitive.vim sources_non_forked/vim-fugitive/doc/fugitive.txt
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
## vim-gitgutter
|
||||
|
||||
A Vim plugin which shows a git diff in the 'gutter' (sign column). It shows which lines have been added, modified, or removed. You can also preview, stage, and undo individual hunks; and stage partial hunks. The plugin also provides a hunk text object.
|
||||
A Vim plugin which shows a git diff in the sign column. It shows which lines have been added, modified, or removed. You can also preview, stage, and undo individual hunks; and stage partial hunks. The plugin also provides a hunk text object.
|
||||
|
||||
The signs are always up to date and the plugin never saves your buffer.
|
||||
|
||||
The name "gitgutter" comes from the Sublime Text 3 plugin which inspired this in 2013.
|
||||
|
||||
Features:
|
||||
|
||||
* Shows signs for added, modified, and removed lines.
|
||||
@ -33,6 +35,10 @@ Constraints:
|
||||
* Supports git only. If you work with other version control systems, I recommend [vim-signify](https://github.com/mhinz/vim-signify).
|
||||
* Relies on the `FocusGained` event. If your terminal doesn't report focus events, either use something like [Terminus][] or set `let g:gitgutter_terminal_reports_focus=0`. For tmux, `set -g focus-events on` in your tmux.conf.
|
||||
|
||||
Compatibility:
|
||||
|
||||
Compatible back to Vim 7.4, and probably 7.3.
|
||||
|
||||
|
||||
### Screenshot
|
||||
|
||||
@ -88,6 +94,10 @@ You can jump between hunks with `[c` and `]c`. You can preview, stage, and undo
|
||||
|
||||
You cannot unstage a staged hunk.
|
||||
|
||||
After updating the signs, the plugin fires the `GitGutter` User autocommand.
|
||||
|
||||
After staging a hunk or part of a hunk, the plugin fires the `GitGutterStage` User autocommand.
|
||||
|
||||
|
||||
#### Activation
|
||||
|
||||
@ -127,12 +137,15 @@ The same caveat applies to line number highlighting as to line highlighting just
|
||||
|
||||
If you switch off both line highlighting and signs, you won't see the sign column.
|
||||
|
||||
To keep your Vim snappy, vim-gitgutter will suppress the signs when a file has more than 500 changes. As soon as the number of changes falls below the limit vim-gitgutter will show the signs again. You can configure the threshold with:
|
||||
In older Vims (pre 8.1.0614 / Neovim 0.4.0) vim-gitgutter will suppress the signs when a file has more than 500 changes, to avoid slowing down the UI. As soon as the number of changes falls below the limit vim-gitgutter will show the signs again. You can configure the threshold with:
|
||||
|
||||
```viml
|
||||
let g:gitgutter_max_signs = 500 " default value
|
||||
let g:gitgutter_max_signs = 500 " default value (Vim < 8.1.0614, Neovim < 0.4.0)
|
||||
let g:gitgutter_max_signs = -1 " default value (otherwise)
|
||||
```
|
||||
|
||||
You can also remove the limit by setting `g:gitgutter_max_signs = -1`.
|
||||
|
||||
#### Hunks
|
||||
|
||||
You can jump between hunks:
|
||||
@ -149,7 +162,17 @@ nmap ]h <Plug>(GitGutterNextHunk)
|
||||
nmap [h <Plug>(GitGutterPrevHunk)
|
||||
```
|
||||
|
||||
You can load all your hunks into the quickfix list with `:GitGutterQuickFix`. Note this ignores any unsaved changes in your buffers. If the option `g:gitgutter_use_location_list` is set, this command will load hunks into the current window's location list instead.
|
||||
When you jump between hunks, a message like `Hunk 4 of 11` is shown on the command line. If you want to turn the message off, you can use:
|
||||
|
||||
```viml
|
||||
let g:gitgutter_show_msg_on_hunk_jumping = 0
|
||||
```
|
||||
|
||||
You can load all your hunks into the quickfix list with `:GitGutterQuickFix`. Note this ignores any unsaved changes in your buffers. If the option `g:gitgutter_use_location_list` is set, this command will load hunks into the current window's location list instead. Use `:copen` (or `:lopen`) to open the quickfix / location list or add a custom command like this:
|
||||
|
||||
```viml
|
||||
command! Gqf GitGutterQuickFix | copen
|
||||
```
|
||||
|
||||
You can stage or undo an individual hunk when your cursor is in it:
|
||||
|
||||
@ -277,19 +300,14 @@ Please note that vim-gitgutter won't override any colours or highlights you've s
|
||||
|
||||
#### Sign column
|
||||
|
||||
By default vim-gitgutter will make the sign column look like the line number column.
|
||||
|
||||
To customise your sign column's background color, first tell vim-gitgutter to leave it alone:
|
||||
Set the `SignColumn` highlight group to change the sign column's colour. For example:
|
||||
|
||||
```viml
|
||||
let g:gitgutter_override_sign_column_highlight = 0
|
||||
```
|
||||
" vim-gitgutter used to do this by default:
|
||||
highlight! link SignColumn LineNr
|
||||
|
||||
And then either update your colorscheme's `SignColumn` highlight group or set it in your vimrc:
|
||||
|
||||
```viml
|
||||
highlight SignColumn ctermbg=whatever " terminal Vim
|
||||
highlight SignColumn guibg=whatever " gVim/MacVim
|
||||
" or you could do this:
|
||||
highlight SignColumn guibg=whatever ctermbg=whatever
|
||||
```
|
||||
|
||||
By default the sign column will appear when there are signs to show and disappear when there aren't. To always have the sign column, add to your vimrc:
|
||||
@ -308,31 +326,22 @@ let g:gitgutter_sign_allow_clobber = 1
|
||||
|
||||
#### Signs' colours and symbols
|
||||
|
||||
By default vim-gitgutter uses your colourscheme's `Diff*` highlight groups' foreground colours for the signs' foreground colours. For example, your `DiffAdd` foreground colour will be used for the `+` sign's foreground colour.
|
||||
If you or your colourscheme has defined `GitGutter*` highlight groups, the plugin will use them for the signs' colours.
|
||||
|
||||
The signs' background colours will all be set to the sign column's background colour.
|
||||
|
||||
If you don't like the default colours, you can either fix your colourscheme's `Diff*` highlights or configure your own `GitGutter*` highlight groups. These groups are:
|
||||
If you want the background colours to match the sign column, but don't want to update the `GitGutter*` groups yourself, you can get the plugin to do it:
|
||||
|
||||
```viml
|
||||
GitGutterAdd " an added line (default: links to DiffAdd)
|
||||
GitGutterChange " a changed line (default: links to DiffChange)
|
||||
GitGutterDelete " at least one removed line (default: links to DiffDelete)
|
||||
GitGutterChangeDelete " a changed line followed by at least one removed line (default: links to GitGutterChange)
|
||||
let g:gitgutter_set_sign_backgrounds = 1
|
||||
```
|
||||
|
||||
You can either set these with `highlight GitGutterAdd {key}={arg}...` or link them to existing highlight groups with, say, `highlight link GitGutterAdd MyDiffAdd`.
|
||||
|
||||
To get vim-gitgutter's original colours (based on git-diff's colours in my terminal):
|
||||
If no `GitGutter*` highlight groups exist, the plugin will check the `Diff*` highlight groups. If their foreground colours differ the plugin will use them; if not, these colours will be used:
|
||||
|
||||
```viml
|
||||
highlight GitGutterAdd guifg=#009900 guibg=<X> ctermfg=2 ctermbg=<Y>
|
||||
highlight GitGutterChange guifg=#bbbb00 guibg=<X> ctermfg=3 ctermbg=<Y>
|
||||
highlight GitGutterDelete guifg=#ff2222 guibg=<X> ctermfg=1 ctermbg=<Y>
|
||||
highlight GitGutterAdd guifg=#009900 ctermfg=2
|
||||
highlight GitGutterChange guifg=#bbbb00 ctermfg=3
|
||||
highlight GitGutterDelete guifg=#ff2222 ctermfg=1
|
||||
```
|
||||
|
||||
– where you would replace `<X>` and `<Y>` with the background colour of your `SignColumn` in the gui and the terminal respectively. For example, with the solarized colorscheme and a dark background, `guibg=#073642` and `ctermbg=0`.
|
||||
|
||||
To customise the symbols, add the following to your `~/.vimrc`:
|
||||
|
||||
```viml
|
||||
@ -340,6 +349,7 @@ 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_removed_above_and_below = '{'
|
||||
let g:gitgutter_sign_modified_removed = 'ww'
|
||||
```
|
||||
|
||||
@ -399,6 +409,8 @@ By default buffers are diffed against the index. However you can diff against a
|
||||
let g:gitgutter_diff_base = '<commit SHA>'
|
||||
```
|
||||
|
||||
If you are looking at a previous version of a file with Fugitive (e.g. via `:0Gclog`), gitgutter sets the diff base to the parent of the current revision.
|
||||
|
||||
This setting is ignored when the diffs are relative to the working tree.
|
||||
|
||||
|
||||
@ -632,16 +644,6 @@ This plugin is for showing changes between the buffer and the index (and staging
|
||||
|
||||
Your colorscheme is configuring the `SignColumn` highlight group weirdly. Please see the section above on customising the sign column.
|
||||
|
||||
> Why are the colours in the preview window weird?
|
||||
|
||||
Probably because your colourscheme doesn't configure the `diff{Added,Changed,Removed}` highlight groups. Try this in `after/syntax/diff.vim`:
|
||||
|
||||
```viml
|
||||
highlight link diffAdded DiffAdd
|
||||
highlight link diffChanged DiffChange
|
||||
highlight link diffRemoved DiffDelete
|
||||
```
|
||||
|
||||
> What happens if I also use another plugin which uses signs (e.g. Syntastic)?
|
||||
|
||||
You can configure whether GitGutter preserves or clobbers other signs using `g:gitgutter_sign_allow_clobber`. Set to `1` to clobber other signs (default on Vim >= 8.1.0614 and NeoVim >= 0.4.0) or `0` to preserve them.
|
||||
@ -657,7 +659,10 @@ Here are some things you can check:
|
||||
* Verify `:echo system("git --version")` succeeds.
|
||||
* Verify your git config is compatible with the version of git returned by the command above.
|
||||
* Verify your Vim supports signs (`:echo has('signs')` should give `1`).
|
||||
* Verify your file is being tracked by git and has unstaged changes.
|
||||
* Verify your file is being tracked by git and has unstaged changes. Check whether the plugin thinks git knows about your file: `:echo b:gitgutter.path` should show the path to the file in the repo.
|
||||
* Execute `:sign place group=gitgutter`; you should see a list of signs.
|
||||
- If the signs are listed: this is a colorscheme / highlight problem. Compare `:highlight GitGutterAdd` with `:highlight SignColumn`.
|
||||
- If no signs are listed: the call to git-diff is probably failing. Add `let g:gitgutter_log=1` to your vimrc, restart, reproduce the problem, and look at the `gitgutter.log` file in the plugin's directory.
|
||||
|
||||
#### When the whole file is marked as added
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
let s:t_string = type('')
|
||||
|
||||
" Primary functions {{{
|
||||
|
||||
function! gitgutter#all(force) abort
|
||||
@ -42,7 +40,7 @@ function! gitgutter#process_buffer(bufnr, force) abort
|
||||
|
||||
if a:force || s:has_fresh_changes(a:bufnr)
|
||||
|
||||
let diff = ''
|
||||
let diff = 'NOT SET'
|
||||
try
|
||||
let diff = gitgutter#diff#run_diff(a:bufnr, g:gitgutter_diff_relative_to, 0)
|
||||
catch /gitgutter not tracked/
|
||||
@ -52,7 +50,7 @@ function! gitgutter#process_buffer(bufnr, force) abort
|
||||
call gitgutter#hunk#reset(a:bufnr)
|
||||
endtry
|
||||
|
||||
if diff != 'async'
|
||||
if diff != 'async' && diff != 'NOT SET'
|
||||
call gitgutter#diff#handler(a:bufnr, diff)
|
||||
endif
|
||||
|
||||
@ -174,11 +172,7 @@ function! gitgutter#setup_maps()
|
||||
endfunction
|
||||
|
||||
function! s:setup_path(bufnr, continuation)
|
||||
let p = gitgutter#utility#repo_path(a:bufnr, 0)
|
||||
|
||||
if type(p) == s:t_string && !empty(p) " if path is known
|
||||
return
|
||||
endif
|
||||
if gitgutter#utility#has_repo_path(a:bufnr) | return | endif
|
||||
|
||||
<<<<<<< HEAD
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'mapped', 1)
|
||||
@ -219,9 +213,17 @@ endfunction
|
||||
" - it ignores unsaved changes in buffers
|
||||
" - it does not change to the repo root
|
||||
function! gitgutter#quickfix()
|
||||
let cmd = g:gitgutter_git_executable.' '.g:gitgutter_git_args.' rev-parse --show-cdup'
|
||||
let path_to_repo = get(systemlist(cmd), 0, '')
|
||||
if !empty(path_to_repo) && path_to_repo[-1:] != '/'
|
||||
let path_to_repo .= '/'
|
||||
endif
|
||||
|
||||
let locations = []
|
||||
let cmd = g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager '.g:gitgutter_git_args.
|
||||
\ ' diff --no-ext-diff --no-color -U0 '.g:gitgutter_diff_args
|
||||
let cmd = g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager'.
|
||||
\ ' diff --no-ext-diff --no-color -U0'.
|
||||
\ ' --src-prefix=a/'.path_to_repo.' --dst-prefix=b/'.path_to_repo.' '.
|
||||
\ g:gitgutter_diff_args. ' '. g:gitgutter_diff_base
|
||||
let diff = systemlist(cmd)
|
||||
let lnum = 0
|
||||
for line in diff
|
||||
|
@ -6,6 +6,8 @@ let s:available = has('nvim') || (
|
||||
\ )
|
||||
\ )
|
||||
|
||||
let s:jobs = {}
|
||||
|
||||
function! gitgutter#async#available()
|
||||
return s:available
|
||||
endfunction
|
||||
@ -28,11 +30,12 @@ function! gitgutter#async#execute(cmd, bufnr, handler) abort
|
||||
\ 'on_exit': function('s:on_exit_nvim')
|
||||
\ }))
|
||||
else
|
||||
call job_start(command, {
|
||||
let job = job_start(command, {
|
||||
\ 'out_cb': function('s:on_stdout_vim', options),
|
||||
\ 'err_cb': function('s:on_stderr_vim', options),
|
||||
\ 'close_cb': function('s:on_exit_vim', options)
|
||||
\ })
|
||||
let s:jobs[s:job_id(job)] = 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@ -83,6 +86,8 @@ endfunction
|
||||
|
||||
function! s:on_exit_vim(channel) dict abort
|
||||
let job = ch_getjob(a:channel)
|
||||
let jobid = s:job_id(job)
|
||||
if has_key(s:jobs, jobid) | unlet s:jobs[jobid] | endif
|
||||
while 1
|
||||
if job_status(job) == 'dead'
|
||||
let exit_code = job_info(job).exitval
|
||||
@ -95,3 +100,8 @@ function! s:on_exit_vim(channel) dict abort
|
||||
call self.handler.out(self.buffer, join(self.stdoutbuffer, "\n"))
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:job_id(job)
|
||||
" Vim
|
||||
return job_info(a:job).process
|
||||
endfunction
|
||||
|
@ -22,16 +22,6 @@ function! gitgutter#debug#debug()
|
||||
call s:separator()
|
||||
|
||||
call s:option('updatetime')
|
||||
call s:option('shell')
|
||||
call s:option('shellcmdflag')
|
||||
call s:option('shellpipe')
|
||||
call s:option('shellquote')
|
||||
call s:option('shellredir')
|
||||
call s:option('shellslash')
|
||||
call s:option('shelltemp')
|
||||
call s:option('shelltype')
|
||||
call s:option('shellxescape')
|
||||
call s:option('shellxquote')
|
||||
endfunction
|
||||
|
||||
|
||||
@ -52,10 +42,10 @@ function! s:git_version()
|
||||
endfunction
|
||||
|
||||
function! s:grep_version()
|
||||
let v = system('grep --version')
|
||||
let v = system(g:gitgutter_grep.' --version')
|
||||
call s:output( substitute(v, '\n$', '', '') )
|
||||
|
||||
let v = system('grep --help')
|
||||
let v = system(g:gitgutter_grep.' --help')
|
||||
call s:output( substitute(v, '\%x00', '', 'g') )
|
||||
endfunction
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
scriptencoding utf8
|
||||
|
||||
let s:nomodeline = (v:version > 703 || (v:version == 703 && has('patch442'))) ? '<nomodeline>' : ''
|
||||
|
||||
let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
|
||||
@ -14,7 +16,6 @@ endfunction
|
||||
|
||||
let s:c_flag = s:git_supports_command_line_config_override()
|
||||
|
||||
|
||||
let s:temp_from = tempname()
|
||||
let s:temp_buffer = tempname()
|
||||
let s:counter = 0
|
||||
@ -122,7 +123,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
|
||||
endif
|
||||
|
||||
" Write file from index to temporary file.
|
||||
let index_name = g:gitgutter_diff_base.':'.gitgutter#utility#repo_path(a:bufnr, 1)
|
||||
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#repo_path(a:bufnr, 1)
|
||||
let cmd .= g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager show '.index_name.' > '.from_file.' && '
|
||||
|
||||
elseif a:from ==# 'working_tree'
|
||||
@ -130,7 +131,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
|
||||
endif
|
||||
|
||||
" Call git-diff.
|
||||
let cmd .= g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager '.g:gitgutter_git_args
|
||||
let cmd .= g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager'
|
||||
if s:c_flag
|
||||
let cmd .= ' -c "diff.autorefreshindex=0"'
|
||||
let cmd .= ' -c "diff.noprefix=false"'
|
||||
@ -184,7 +185,7 @@ function! gitgutter#diff#handler(bufnr, diff) abort
|
||||
let modified_lines = gitgutter#diff#process_hunks(a:bufnr, gitgutter#hunk#hunks(a:bufnr))
|
||||
|
||||
let signs_count = len(modified_lines)
|
||||
if signs_count > g:gitgutter_max_signs
|
||||
if g:gitgutter_max_signs != -1 && signs_count > g:gitgutter_max_signs
|
||||
call gitgutter#utility#warn_once(a:bufnr, printf(
|
||||
\ 'exceeded maximum number of signs (%d > %d, configured by g:gitgutter_max_signs).',
|
||||
\ signs_count, g:gitgutter_max_signs), 'max_signs')
|
||||
@ -402,12 +403,19 @@ function! s:write_buffer(bufnr, file)
|
||||
let bufcontents[0]=''.bufcontents[0]
|
||||
endif
|
||||
|
||||
call writefile(bufcontents, a:file, 'b')
|
||||
" The file we are writing to is a temporary file. Sometimes the parent
|
||||
" directory is deleted outside Vim but, because Vim caches the directory
|
||||
" name at startup and does not check for its existence subsequently, Vim
|
||||
" does not realise. This causes E482 errors.
|
||||
try
|
||||
call writefile(bufcontents, a:file, 'b')
|
||||
catch /E482/
|
||||
call mkdir(fnamemodify(a:file, ':h'), '', '0700')
|
||||
call writefile(bufcontents, a:file, 'b')
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:save_last_seen_change(bufnr) abort
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'tick', getbufvar(a:bufnr, 'changedtick'))
|
||||
endfunction
|
||||
|
||||
|
||||
|
@ -64,14 +64,6 @@ function! gitgutter#highlight#linenr_toggle() abort
|
||||
endfunction
|
||||
|
||||
|
||||
function! gitgutter#highlight#define_sign_column_highlight() abort
|
||||
if g:gitgutter_override_sign_column_highlight
|
||||
highlight! link SignColumn LineNr
|
||||
else
|
||||
highlight default link SignColumn LineNr
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! gitgutter#highlight#define_highlights() abort
|
||||
let [guibg, ctermbg] = s:get_background_colors('SignColumn')
|
||||
|
||||
@ -84,12 +76,24 @@ function! gitgutter#highlight#define_highlights() abort
|
||||
highlight default link GitGutterChangeDeleteInvisible GitGutterChangeInvisible
|
||||
|
||||
" When they are visible.
|
||||
" By default use Diff* foreground colors with SignColumn's background.
|
||||
for type in ['Add', 'Change', 'Delete']
|
||||
let [guifg, ctermfg] = s:get_foreground_colors('Diff'.type)
|
||||
execute "highlight GitGutter".type."Default guifg=".guifg." guibg=".guibg." ctermfg=".ctermfg." ctermbg=".ctermbg
|
||||
execute "highlight default link GitGutter".type." GitGutter".type."Default"
|
||||
for type in ["Add", "Change", "Delete"]
|
||||
if hlexists("GitGutter".type) && s:get_foreground_colors("GitGutter".type) != ['NONE', 'NONE']
|
||||
if g:gitgutter_set_sign_backgrounds
|
||||
execute "highlight GitGutter".type." guibg=".guibg." ctermbg=".ctermbg
|
||||
endif
|
||||
continue
|
||||
elseif s:useful_diff_colours()
|
||||
let [guifg, ctermfg] = s:get_foreground_colors('Diff'.type)
|
||||
else
|
||||
let [guifg, ctermfg] = s:get_foreground_fallback_colors(type)
|
||||
endif
|
||||
execute "highlight GitGutter".type." guifg=".guifg." guibg=".guibg." ctermfg=".ctermfg." ctermbg=".ctermbg
|
||||
endfor
|
||||
|
||||
if hlexists("GitGutterChangeDelete") && g:gitgutter_set_sign_backgrounds
|
||||
execute "highlight GitGutterChangeDelete guibg=".guibg." ctermbg=".ctermbg
|
||||
endif
|
||||
|
||||
highlight default link GitGutterChangeDelete GitGutterChange
|
||||
|
||||
" Highlights used for the whole line.
|
||||
@ -107,6 +111,14 @@ function! gitgutter#highlight#define_highlights() abort
|
||||
" Highlights used intra line.
|
||||
highlight GitGutterAddIntraLine gui=reverse cterm=reverse
|
||||
highlight GitGutterDeleteIntraLine gui=reverse cterm=reverse
|
||||
" Set diff syntax colours (used in the preview window) - diffAdded,diffChanged,diffRemoved -
|
||||
" to match the signs, if not set aleady.
|
||||
for [dtype,type] in [['Added','Add'], ['Changed','Change'], ['Removed','Delete']]
|
||||
if !hlexists('diff'.dtype)
|
||||
let [guifg, ctermfg] = s:get_foreground_colors('GitGutter'.type)
|
||||
execute "highlight diff".dtype." guifg=".guifg." ctermfg=".ctermfg." guibg=NONE ctermbg=NONE"
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! gitgutter#highlight#define_signs() abort
|
||||
@ -217,3 +229,20 @@ function! s:get_background_colors(group) abort
|
||||
let guibg = s:get_hl(a:group, 'bg', 'gui')
|
||||
return [guibg, ctermbg]
|
||||
endfunction
|
||||
|
||||
function! s:useful_diff_colours()
|
||||
let [guifg_add, ctermfg_add] = s:get_foreground_colors('DiffAdd')
|
||||
let [guifg_del, ctermfg_del] = s:get_foreground_colors('DiffDelete')
|
||||
|
||||
return guifg_add != guifg_del && ctermfg_add != ctermfg_del
|
||||
endfunction
|
||||
|
||||
function! s:get_foreground_fallback_colors(type)
|
||||
if a:type == 'Add'
|
||||
return ['#009900', '2']
|
||||
elseif a:type == 'Change'
|
||||
return ['#bbbb00', '3']
|
||||
elseif a:type == 'Delete'
|
||||
return ['#ff2222', '1']
|
||||
endif
|
||||
endfunction
|
||||
|
@ -1,4 +1,6 @@
|
||||
let s:winid = 0
|
||||
let s:preview_bufnr = 0
|
||||
let s:nomodeline = (v:version > 703 || (v:version == 703 && has('patch442'))) ? '<nomodeline>' : ''
|
||||
|
||||
function! gitgutter#hunk#set_hunks(bufnr, hunks) abort
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'hunks', a:hunks)
|
||||
@ -44,39 +46,57 @@ endfunction
|
||||
|
||||
function! gitgutter#hunk#next_hunk(count) abort
|
||||
let bufnr = bufnr('')
|
||||
if gitgutter#utility#is_active(bufnr)
|
||||
let current_line = line('.')
|
||||
let hunk_count = 0
|
||||
for hunk in gitgutter#hunk#hunks(bufnr)
|
||||
if hunk[2] > current_line
|
||||
let hunk_count += 1
|
||||
if hunk_count == a:count
|
||||
execute 'normal!' hunk[2] . 'Gzv'
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
call gitgutter#utility#warn('No more hunks')
|
||||
if !gitgutter#utility#is_active(bufnr) | return | endif
|
||||
|
||||
let hunks = gitgutter#hunk#hunks(bufnr)
|
||||
if empty(hunks)
|
||||
call gitgutter#utility#warn('No hunks in file')
|
||||
return
|
||||
endif
|
||||
|
||||
let current_line = line('.')
|
||||
let hunk_count = 0
|
||||
for hunk in hunks
|
||||
if hunk[2] > current_line
|
||||
let hunk_count += 1
|
||||
if hunk_count == a:count
|
||||
execute 'normal!' hunk[2] . 'Gzv'
|
||||
if g:gitgutter_show_msg_on_hunk_jumping
|
||||
redraw | echo printf('Hunk %d of %d', index(hunks, hunk) + 1, len(hunks))
|
||||
endif
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
call gitgutter#utility#warn('No more hunks')
|
||||
endfunction
|
||||
|
||||
function! gitgutter#hunk#prev_hunk(count) abort
|
||||
let bufnr = bufnr('')
|
||||
if gitgutter#utility#is_active(bufnr)
|
||||
let current_line = line('.')
|
||||
let hunk_count = 0
|
||||
for hunk in reverse(copy(gitgutter#hunk#hunks(bufnr)))
|
||||
if hunk[2] < current_line
|
||||
let hunk_count += 1
|
||||
if hunk_count == a:count
|
||||
let target = hunk[2] == 0 ? 1 : hunk[2]
|
||||
execute 'normal!' target . 'Gzv'
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
call gitgutter#utility#warn('No previous hunks')
|
||||
if !gitgutter#utility#is_active(bufnr) | return | endif
|
||||
|
||||
let hunks = gitgutter#hunk#hunks(bufnr)
|
||||
if empty(hunks)
|
||||
call gitgutter#utility#warn('No hunks in file')
|
||||
return
|
||||
endif
|
||||
|
||||
let current_line = line('.')
|
||||
let hunk_count = 0
|
||||
for hunk in reverse(copy(hunks))
|
||||
if hunk[2] < current_line
|
||||
let hunk_count += 1
|
||||
if hunk_count == a:count
|
||||
let target = hunk[2] == 0 ? 1 : hunk[2]
|
||||
execute 'normal!' target . 'Gzv'
|
||||
if g:gitgutter_show_msg_on_hunk_jumping
|
||||
redraw | echo printf('Hunk %d of %d', index(hunks, hunk) + 1, len(hunks))
|
||||
endif
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
call gitgutter#utility#warn('No previous hunks')
|
||||
endfunction
|
||||
|
||||
" Returns the hunk the cursor is currently in or an empty list if the cursor
|
||||
@ -172,6 +192,8 @@ endfunction
|
||||
|
||||
|
||||
function! gitgutter#hunk#stage(...) abort
|
||||
if !s:in_hunk_preview_window() && !gitgutter#utility#has_repo_path(bufnr('')) | return | endif
|
||||
|
||||
if a:0 && (a:1 != 1 || a:2 != line('$'))
|
||||
call s:hunk_op(function('s:stage'), a:1, a:2)
|
||||
else
|
||||
@ -181,11 +203,15 @@ function! gitgutter#hunk#stage(...) abort
|
||||
endfunction
|
||||
|
||||
function! gitgutter#hunk#undo() abort
|
||||
if !gitgutter#utility#has_repo_path(bufnr('')) | return | endif
|
||||
|
||||
call s:hunk_op(function('s:undo'))
|
||||
silent! call repeat#set("\<Plug>(GitGutterUndoHunk)", -1)
|
||||
endfunction
|
||||
|
||||
function! gitgutter#hunk#preview() abort
|
||||
if !gitgutter#utility#has_repo_path(bufnr('')) | return | endif
|
||||
|
||||
call s:hunk_op(function('s:preview'))
|
||||
silent! call repeat#set("\<Plug>(GitGutterPreviewHunk)", -1)
|
||||
endfunction
|
||||
@ -268,6 +294,10 @@ function! s:stage(hunk_diff)
|
||||
\ diff)
|
||||
if v:shell_error
|
||||
call gitgutter#utility#warn('patch does not apply')
|
||||
else
|
||||
if exists('#User#GitGutterStage')
|
||||
execute 'doautocmd' s:nomodeline 'User GitGutterStage'
|
||||
endif
|
||||
endif
|
||||
|
||||
" Refresh gitgutter's view of buffer.
|
||||
@ -428,13 +458,23 @@ function! s:open_hunk_preview_window()
|
||||
endif
|
||||
|
||||
silent! wincmd P
|
||||
if !&previewwindow
|
||||
if &previewwindow
|
||||
file gitgutter://hunk-preview
|
||||
else
|
||||
noautocmd execute g:gitgutter_preview_win_location &previewheight 'new gitgutter://hunk-preview'
|
||||
let s:winid = win_getid()
|
||||
doautocmd WinEnter
|
||||
set previewwindow
|
||||
setlocal filetype=diff buftype=acwrite bufhidden=delete
|
||||
" Reset some defaults in case someone else has changed them.
|
||||
setlocal noreadonly modifiable noswapfile
|
||||
endif
|
||||
if exists('*win_getid')
|
||||
let s:winid = win_getid()
|
||||
else
|
||||
let s:preview_bufnr = bufnr('')
|
||||
endif
|
||||
setlocal filetype=diff buftype=acwrite bufhidden=delete
|
||||
" Reset some defaults in case someone else has changed them.
|
||||
setlocal noreadonly modifiable noswapfile
|
||||
if g:gitgutter_close_preview_on_escape
|
||||
nnoremap <buffer> <silent> <Esc> :pclose<CR>
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@ -443,17 +483,22 @@ endfunction
|
||||
" Preview window: assumes cursor is in preview window.
|
||||
function! s:populate_hunk_preview_window(header, body)
|
||||
let body_length = len(a:body)
|
||||
let height = min([body_length, &previewheight])
|
||||
|
||||
if g:gitgutter_preview_win_floating
|
||||
if exists('*nvim_open_win')
|
||||
let height = min([body_length, &previewheight])
|
||||
|
||||
" Assumes cursor is not in previewing window.
|
||||
call nvim_buf_set_var(winbufnr(s:winid), 'hunk_header', a:header)
|
||||
|
||||
let [_scrolloff, &scrolloff] = [&scrolloff, 0]
|
||||
|
||||
let width = max(map(copy(a:body), 'strdisplaywidth(v:val)'))
|
||||
call nvim_win_set_width(s:winid, width)
|
||||
call nvim_win_set_height(s:winid, height)
|
||||
|
||||
let &scrolloff=_scrolloff
|
||||
|
||||
call nvim_buf_set_lines(winbufnr(s:winid), 0, -1, v:false, [])
|
||||
call nvim_buf_set_lines(winbufnr(s:winid), 0, -1, v:false, a:body)
|
||||
call nvim_buf_set_option(winbufnr(s:winid), 'modified', v:false)
|
||||
@ -479,12 +524,16 @@ function! s:populate_hunk_preview_window(header, body)
|
||||
|
||||
else
|
||||
let b:hunk_header = a:header
|
||||
execute 'resize' height
|
||||
|
||||
%delete _
|
||||
call setline(1, a:body)
|
||||
setlocal nomodified
|
||||
|
||||
normal! G$
|
||||
let height = min([winline(), &previewheight])
|
||||
execute 'resize' height
|
||||
1
|
||||
|
||||
call clearmatches()
|
||||
for region in gitgutter#diff_highlight#process(a:body)
|
||||
let group = region[1] == '+' ? 'GitGutterAddIntraLine' : 'GitGutterDeleteIntraLine'
|
||||
@ -499,18 +548,21 @@ endfunction
|
||||
function! s:enable_staging_from_hunk_preview_window()
|
||||
augroup gitgutter_hunk_preview
|
||||
autocmd!
|
||||
execute 'autocmd BufWriteCmd <buffer='.winbufnr(s:winid).'> GitGutterStageHunk'
|
||||
let bufnr = s:winid != 0 ? winbufnr(s:winid) : s:preview_bufnr
|
||||
execute 'autocmd BufWriteCmd <buffer='.bufnr.'> GitGutterStageHunk'
|
||||
augroup END
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:goto_original_window()
|
||||
noautocmd wincmd p
|
||||
doautocmd WinEnter
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:close_hunk_preview_window()
|
||||
call setbufvar(winbufnr(s:winid), '&modified', 0)
|
||||
let bufnr = s:winid != 0 ? winbufnr(s:winid) : s:preview_bufnr
|
||||
call setbufvar(bufnr, '&modified', 0)
|
||||
|
||||
if g:gitgutter_preview_win_floating
|
||||
if win_id2win(s:winid) > 0
|
||||
@ -521,4 +573,5 @@ function! s:close_hunk_preview_window()
|
||||
endif
|
||||
|
||||
let s:winid = 0
|
||||
let s:preview_bufnr = 0
|
||||
endfunction
|
||||
|
@ -9,25 +9,19 @@ endfunction
|
||||
function! gitgutter#utility#setbufvar(buffer, varname, val)
|
||||
let buffer = +a:buffer
|
||||
" Default value for getbufvar() was introduced in Vim 7.3.831.
|
||||
let bvars = getbufvar(buffer, '')
|
||||
if empty(bvars)
|
||||
let bvars = {}
|
||||
endif
|
||||
let dict = get(bvars, 'gitgutter', {})
|
||||
let needs_setting = empty(dict)
|
||||
let dict[a:varname] = a:val
|
||||
if needs_setting
|
||||
call setbufvar(buffer, 'gitgutter', dict)
|
||||
let ggvars = getbufvar(buffer, 'gitgutter')
|
||||
if type(ggvars) == type('')
|
||||
unlet ggvars
|
||||
let ggvars = {}
|
||||
call setbufvar(buffer, 'gitgutter', ggvars)
|
||||
endif
|
||||
let ggvars[a:varname] = a:val
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#getbufvar(buffer, varname, ...)
|
||||
let bvars = getbufvar(a:buffer, '')
|
||||
if !empty(bvars)
|
||||
let dict = get(bvars, 'gitgutter', {})
|
||||
if has_key(dict, a:varname)
|
||||
return dict[a:varname]
|
||||
endif
|
||||
let ggvars = getbufvar(a:buffer, 'gitgutter')
|
||||
if type(ggvars) == type({}) && has_key(ggvars, a:varname)
|
||||
return ggvars[a:varname]
|
||||
endif
|
||||
if a:0
|
||||
return a:1
|
||||
@ -105,6 +99,10 @@ function! gitgutter#utility#system(cmd, ...) abort
|
||||
return output
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#has_repo_path(bufnr)
|
||||
return index(['', -1, -2], gitgutter#utility#repo_path(a:bufnr, 0)) == -1
|
||||
endfunction
|
||||
|
||||
" Path of file relative to repo root.
|
||||
"
|
||||
" * empty string - not set
|
||||
@ -112,7 +110,7 @@ endfunction
|
||||
" * -1 - pending
|
||||
" * -2 - not tracked by git
|
||||
function! gitgutter#utility#repo_path(bufnr, shellesc) abort
|
||||
let p = gitgutter#utility#getbufvar(a:bufnr, 'path')
|
||||
let p = gitgutter#utility#getbufvar(a:bufnr, 'path', '')
|
||||
return a:shellesc ? gitgutter#utility#shellescape(p) : p
|
||||
endfunction
|
||||
|
||||
@ -164,7 +162,7 @@ endfunction
|
||||
|
||||
|
||||
function! gitgutter#utility#cd_cmd(bufnr, cmd) abort
|
||||
let cd = s:unc_path(a:bufnr) ? 'pushd' : (gitgutter#utility#windows() ? 'cd /d' : 'cd')
|
||||
let cd = s:unc_path(a:bufnr) ? 'pushd' : (gitgutter#utility#windows() && s:dos_shell() ? 'cd /d' : 'cd')
|
||||
return cd.' '.s:dir(a:bufnr).' && '.a:cmd
|
||||
endfunction
|
||||
|
||||
@ -172,6 +170,10 @@ function! s:unc_path(bufnr)
|
||||
return s:abs_path(a:bufnr, 0) =~ '^\\\\'
|
||||
endfunction
|
||||
|
||||
function! s:dos_shell()
|
||||
return &shell == 'cmd.exe' || &shell == 'command.com'
|
||||
endfunction
|
||||
|
||||
function! s:use_known_shell() abort
|
||||
if has('unix') && &shell !=# 'sh'
|
||||
let [s:shell, s:shellcmdflag, s:shellredir] = [&shell, &shellcmdflag, &shellredir]
|
||||
@ -186,8 +188,21 @@ function! s:restore_shell() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#get_diff_base(bufnr)
|
||||
let p = resolve(expand('#'.a:bufnr.':p'))
|
||||
let ml = matchlist(p, '\v^fugitive:/.*/(\x{40,})/')
|
||||
if !empty(ml) && !empty(ml[1])
|
||||
return ml[1].'^'
|
||||
endif
|
||||
return g:gitgutter_diff_base
|
||||
endfunction
|
||||
|
||||
function! s:abs_path(bufnr, shellesc)
|
||||
let p = resolve(expand('#'.a:bufnr.':p'))
|
||||
|
||||
" Remove extra parts from fugitive's filepaths
|
||||
let p = substitute(substitute(p, '^fugitive:', '', ''), '\v\.git/\x{40,}/', '', '')
|
||||
|
||||
return a:shellesc ? gitgutter#utility#shellescape(p) : p
|
||||
endfunction
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
*gitgutter.txt* A Vim plugin which shows a git diff in the gutter.
|
||||
|
||||
|
||||
Vim Git Gutter
|
||||
Vim GitGutter
|
||||
|
||||
|
||||
Author: Andy Stewart <https://airbladesoftware.com/>
|
||||
@ -27,13 +27,16 @@ CONTENTS *gitgutter*
|
||||
===============================================================================
|
||||
INTRODUCTION *gitgutter-introduction*
|
||||
|
||||
GitGutter is a Vim plugin which shows a git diff in the 'gutter' (sign column).
|
||||
GitGutter is a Vim plugin which shows a git diff in the sign column.
|
||||
It shows which lines have been added, modified, or removed. You can also
|
||||
preview, stage, and undo individual hunks. The plugin also provides a hunk
|
||||
text object.
|
||||
|
||||
The signs are always up to date and the plugin never saves your buffer.
|
||||
|
||||
The name "gitgutter" comes from the Sublime Text 3 plugin which inspired this
|
||||
one in 2013.
|
||||
|
||||
|
||||
===============================================================================
|
||||
INSTALLATION *gitgutter-installation*
|
||||
@ -143,7 +146,13 @@ Commands for jumping between hunks:~
|
||||
:GitGutterQuickFix Load all hunks into the |quickfix| list. Note this
|
||||
ignores any unsaved changes in your buffers. The
|
||||
|g:gitgutter_use_location_list| option can be set to
|
||||
populate the location list of the current window instead
|
||||
populate the location list of the current window
|
||||
instead. Use |:copen| (or |:lopen|) to open a buffer
|
||||
containing the search results in linked form; or add a
|
||||
custom command like this:
|
||||
>
|
||||
command! Gqf GitGutterQuickFix | copen
|
||||
<
|
||||
|
||||
|
||||
Commands for operating on a hunk:~
|
||||
@ -177,7 +186,7 @@ Commands for folds:~
|
||||
|
||||
|
||||
===============================================================================
|
||||
AUTOCOMMAND *gitgutter-autocommand*
|
||||
AUTOCOMMANDS *gitgutter-autocommands*
|
||||
|
||||
User GitGutter~
|
||||
|
||||
@ -189,6 +198,10 @@ event GitGutter. You can listen for this event, for example:
|
||||
A dictionary `g:gitgutter_hook_context` is made available during its execution,
|
||||
which contains an entry `bufnr` that contains the buffer number being updated.
|
||||
|
||||
User GitGutterStage~
|
||||
|
||||
After staging a hunk or part of a hunk vim-gitgutter fires a |User| |autocmd|
|
||||
with the event GitGutterStage. Staging always happens in the current buffer.
|
||||
|
||||
===============================================================================
|
||||
MAPPINGS *gitgutter-mappings*
|
||||
@ -299,11 +312,16 @@ Signs:~
|
||||
|g:gitgutter_sign_removed|
|
||||
|g:gitgutter_sign_removed_first_line|
|
||||
|g:gitgutter_sign_modified_removed|
|
||||
|g:gitgutter_override_sign_column_highlight|
|
||||
|g:gitgutter_set_sign_backgrounds|
|
||||
|
||||
Hunk jumping:~
|
||||
|
||||
|g:gitgutter_show_msg_on_hunk_jumping|
|
||||
|
||||
Hunk previews:~
|
||||
|
||||
|g:gitgutter_preview_win_floating|
|
||||
|g:gitgutter_close_preview_on_escape|
|
||||
|
||||
Terminal:~
|
||||
|
||||
@ -366,6 +384,9 @@ a revision instead. For example:
|
||||
let g:gitgutter_diff_base = '<some commit SHA>'
|
||||
<
|
||||
|
||||
If you are looking at a previous version of a file with Fugitive (e.g.
|
||||
via :0Gclog), gitgutter sets the diff base to the parent of the current revision.
|
||||
|
||||
This setting is ignore when the diff is relative to the working tree
|
||||
(|g:gitgutter_diff_relative_to|).
|
||||
|
||||
@ -402,13 +423,16 @@ Default: 0
|
||||
Determines whether or not to show line number highlights.
|
||||
|
||||
*g:gitgutter_max_signs*
|
||||
Default: 500
|
||||
Default: 500 (Vim < 8.1.0614, Neovim < 0.4.0)
|
||||
-1 (otherwise)
|
||||
|
||||
Sets the maximum number of signs to show in a buffer. Vim is slow at updating
|
||||
signs, so to avoid slowing down the GUI the number of signs is capped. When
|
||||
the number of changed lines exceeds this value, the plugin removes all signs
|
||||
and displays a warning message.
|
||||
|
||||
When set to -1 the limit is not applied.
|
||||
|
||||
*g:gitgutter_sign_priority*
|
||||
Default: 10
|
||||
|
||||
@ -425,6 +449,7 @@ will not preserve non-gitgutter signs.
|
||||
*g:gitgutter_sign_modified*
|
||||
*g:gitgutter_sign_removed*
|
||||
*g:gitgutter_sign_removed_first_line*
|
||||
*g:gitgutter_sign_removed_above_and_below*
|
||||
*g:gitgutter_sign_modified_removed*
|
||||
Defaults:
|
||||
>
|
||||
@ -432,31 +457,20 @@ Defaults:
|
||||
let g:gitgutter_sign_modified = '~'
|
||||
let g:gitgutter_sign_removed = '_'
|
||||
let g:gitgutter_sign_removed_first_line = '‾'
|
||||
let g:gitgutter_sign_removed_above_and_below = '_¯'
|
||||
let g:gitgutter_sign_modified_removed = '~_'
|
||||
<
|
||||
You can use unicode characters but not images. Signs must not take up more than
|
||||
2 columns.
|
||||
|
||||
*g:gitgutter_override_sign_column_highlight*
|
||||
Default: 1
|
||||
*g:gitgutter_set_sign_backgrounds*
|
||||
Default: 0
|
||||
|
||||
Controls whether to make the sign column look like the line-number column (i.e.
|
||||
the |hl-LineNr| highlight group).
|
||||
|
||||
To customise your sign column's background color, first tell vim-gitgutter to
|
||||
leave it alone:
|
||||
>
|
||||
let g:gitgutter_override_sign_column_highlight = 0
|
||||
<
|
||||
|
||||
And then either update your colorscheme's |hlSignColumn| highlight group or set
|
||||
it in your |vimrc|:
|
||||
|
||||
Desired appearance Command ~
|
||||
Same as line-number column highlight clear SignColumn
|
||||
User-defined (terminal Vim) highlight SignColumn ctermbg={whatever}
|
||||
User-defined (graphical Vim) highlight SignColumn guibg={whatever}
|
||||
Only applies to existing GitGutter* highlight groups. See
|
||||
|gitgutter-highlights|.
|
||||
|
||||
Controls whether to override the signs' background colours to match the
|
||||
|hl-SignColumn|.
|
||||
|
||||
*g:gitgutter_preview_win_floating*
|
||||
Default: 0 (Vim)
|
||||
@ -467,6 +481,11 @@ Whether to use floating/popup windows for hunk previews. Note that if you use
|
||||
popup windows on Vim you will not be able to stage partial hunks via the
|
||||
preview window.
|
||||
|
||||
*g:gitgutter_close_preview_on_escape*
|
||||
Default: 0
|
||||
|
||||
Whether pressing <Esc> in a non-floating preview window closes it.
|
||||
|
||||
*g:gitgutter_terminal_reports_focus*
|
||||
Default: 1
|
||||
|
||||
@ -515,24 +534,27 @@ Default: 0
|
||||
When switched on, the :GitGutterQuickFix command populates the location list
|
||||
of the current window instead of the global quickfix list.
|
||||
|
||||
*g:gitgutter_show_msg_on_hunk_jumping*
|
||||
Default: 1
|
||||
|
||||
When switched on, a message like "Hunk 4 of 11" is shown on hunk jumping.
|
||||
|
||||
|
||||
===============================================================================
|
||||
HIGHLIGHTS *gitgutter-highlights*
|
||||
|
||||
To change the signs' colours, set up the following highlight groups in your
|
||||
colorscheme or |vimrc|:
|
||||
To change the signs' colours, specify these highlight groups in your |vimrc|:
|
||||
>
|
||||
GitGutterAdd " an added line
|
||||
GitGutterChange " a changed line
|
||||
GitGutterDelete " at least one removed line
|
||||
GitGutterChangeDelete " a changed line followed by at least one removed line
|
||||
highlight GitGutterAdd guifg=#009900 ctermfg=2
|
||||
highlight GitGutterChange guifg=#bbbb00 ctermfg=3
|
||||
highlight GitGutterDelete guifg=#ff2222 ctermfg=1
|
||||
<
|
||||
|
||||
You can either set these with `highlight GitGutterAdd {key}={arg}...` or link
|
||||
them to existing highlight groups with, say:
|
||||
>
|
||||
highlight link GitGutterAdd MyDiffAdd
|
||||
<
|
||||
See |highlight-guifg| and |highlight-ctermfg| for the values you can use.
|
||||
|
||||
If you do not like the signs' background colours and you do not want to update
|
||||
the GitGutter* highlight groups yourself, you can get the plugin to do it
|
||||
|g:gitgutter_set_sign_backgrounds|.
|
||||
|
||||
To change the line highlights, set up the following highlight groups in your
|
||||
colorscheme or |vimrc|:
|
||||
@ -589,8 +611,11 @@ c. Why can't I unstage staged changes?
|
||||
d. Why are the colours in the sign column weird?
|
||||
|
||||
Your colorscheme is configuring the |hl-SignColumn| highlight group weirdly.
|
||||
Please see |g:gitgutter_override_sign_column_highlight| on customising the
|
||||
sign column.
|
||||
Here are two ways you could change the colours:
|
||||
>
|
||||
highlight! link SignColumn LineNr
|
||||
highlight SignColumn guibg=whatever ctermbg=whatever
|
||||
<
|
||||
|
||||
e. What happens if I also use another plugin which uses signs (e.g. Syntastic)?
|
||||
|
||||
@ -629,6 +654,22 @@ When no signs are showing at all:~
|
||||
<
|
||||
If the result is -2, the plugin thinks your file is not tracked by git.
|
||||
|
||||
6. Check whether the signs have been placed:
|
||||
>
|
||||
:sign place group=gitgutter
|
||||
<
|
||||
If you see a list of signs, this is a colorscheme / highlight problem.
|
||||
Compare these two highlight values:
|
||||
>
|
||||
:highlight GitGutterAdd
|
||||
:highlight SignColumn
|
||||
<
|
||||
If no signs are listed, the call to git-diff is probably failing. Turn on
|
||||
logging by adding the following to your vimrc, restart, reproduce the problem,
|
||||
and examing the gitgutter.log file in the plugin's directory.
|
||||
>
|
||||
let g:gitgutter_log = 1
|
||||
<
|
||||
|
||||
When the whole file is marked as added:~
|
||||
|
||||
|
@ -12,64 +12,72 @@ if v:version < 703 || (v:version == 703 && !has("patch105"))
|
||||
finish
|
||||
endif
|
||||
|
||||
function! s:set(var, default) abort
|
||||
if !exists(a:var)
|
||||
if type(a:default)
|
||||
execute 'let' a:var '=' string(a:default)
|
||||
else
|
||||
execute 'let' a:var '=' a:default
|
||||
endif
|
||||
let s:nomodeline = (v:version > 703 || (v:version == 703 && has('patch442'))) ? '<nomodeline>' : ''
|
||||
|
||||
function! s:obsolete(var)
|
||||
if exists(a:var)
|
||||
call gitgutter#utility#warn(a:var.' is obsolete and has no effect.')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
call s:set('g:gitgutter_preview_win_location', 'bo')
|
||||
|
||||
let g:gitgutter_preview_win_location = get(g:, 'gitgutter_preview_win_location', 'bo')
|
||||
if exists('*nvim_open_win')
|
||||
call s:set('g:gitgutter_preview_win_floating', 1)
|
||||
let g:gitgutter_preview_win_floating = get(g:, 'gitgutter_preview_win_floating', 1)
|
||||
else
|
||||
call s:set('g:gitgutter_preview_win_floating', 0)
|
||||
let g:gitgutter_preview_win_floating = get(g:, 'gitgutter_preview_win_floating', 0)
|
||||
endif
|
||||
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_priority', 10)
|
||||
let g:gitgutter_enabled = get(g:, 'gitgutter_enabled', 1)
|
||||
if exists('*sign_unplace')
|
||||
let g:gitgutter_max_signs = get(g:, 'gitgutter_max_signs', -1)
|
||||
else
|
||||
let g:gitgutter_max_signs = get(g:, 'gitgutter_max_signs', 500)
|
||||
endif
|
||||
let g:gitgutter_signs = get(g:, 'gitgutter_signs', 1)
|
||||
let g:gitgutter_highlight_lines = get(g:, 'gitgutter_highlight_lines', 0)
|
||||
let g:gitgutter_highlight_linenrs = get(g:, 'gitgutter_highlight_linenrs', 0)
|
||||
let g:gitgutter_sign_priority = get(g:, 'gitgutter_sign_priority', 10)
|
||||
" Nvim 0.4.0 has an expanding sign column
|
||||
" The sign_place() function supports sign priority.
|
||||
if (has('nvim-0.4.0') || exists('*sign_place')) && !exists('g:gitgutter_sign_allow_clobber')
|
||||
let g:gitgutter_sign_allow_clobber = 1
|
||||
endif
|
||||
call s:set('g:gitgutter_sign_allow_clobber', 0)
|
||||
call s:set('g:gitgutter_override_sign_column_highlight', 1)
|
||||
call s:set('g:gitgutter_sign_added', '+')
|
||||
call s:set('g:gitgutter_sign_modified', '~')
|
||||
call s:set('g:gitgutter_sign_removed', '_')
|
||||
let g:gitgutter_sign_allow_clobber = get(g:, 'gitgutter_sign_allow_clobber', 0)
|
||||
let g:gitgutter_set_sign_backgrounds = get(g:, 'gitgutter_set_sign_backgrounds', 0)
|
||||
let g:gitgutter_sign_added = get(g:, 'gitgutter_sign_added', '+')
|
||||
let g:gitgutter_sign_modified = get(g:, 'gitgutter_sign_modified', '~')
|
||||
let g:gitgutter_sign_removed = get(g:, 'gitgutter_sign_removed', '_')
|
||||
|
||||
if gitgutter#utility#supports_overscore_sign()
|
||||
call s:set('g:gitgutter_sign_removed_first_line', '‾')
|
||||
let g:gitgutter_sign_removed_first_line = get(g:, 'gitgutter_sign_removed_first_line', '‾')
|
||||
else
|
||||
call s:set('g:gitgutter_sign_removed_first_line', '_^')
|
||||
let g:gitgutter_sign_removed_first_line = get(g:, 'gitgutter_sign_removed_first_line', '_^')
|
||||
endif
|
||||
|
||||
call s:set('g:gitgutter_sign_removed_above_and_below', '[')
|
||||
call s:set('g:gitgutter_sign_modified_removed', '~_')
|
||||
call s:set('g:gitgutter_git_args', '')
|
||||
call s:set('g:gitgutter_diff_relative_to', 'index')
|
||||
call s:set('g:gitgutter_diff_args', '')
|
||||
call s:set('g:gitgutter_diff_base', '')
|
||||
call s:set('g:gitgutter_map_keys', 1)
|
||||
call s:set('g:gitgutter_terminal_reports_focus', 1)
|
||||
call s:set('g:gitgutter_async', 1)
|
||||
call s:set('g:gitgutter_log', 0)
|
||||
call s:set('g:gitgutter_use_location_list', 0)
|
||||
let g:gitgutter_sign_removed_above_and_below = get(g:, 'gitgutter_sign_removed_above_and_below', '_¯')
|
||||
let g:gitgutter_sign_modified_removed = get(g:, 'gitgutter_sign_modified_removed', '~_')
|
||||
let g:gitgutter_git_args = get(g:, 'gitgutter_git_args', '')
|
||||
let g:gitgutter_diff_relative_to = get(g:, 'gitgutter_diff_relative_to', 'index')
|
||||
let g:gitgutter_diff_args = get(g:, 'gitgutter_diff_args', '')
|
||||
let g:gitgutter_diff_base = get(g:, 'gitgutter_diff_base', '')
|
||||
let g:gitgutter_map_keys = get(g:, 'gitgutter_map_keys', 1)
|
||||
let g:gitgutter_terminal_reports_focus = get(g:, 'gitgutter_terminal_reports_focus', 1)
|
||||
let g:gitgutter_async = get(g:, 'gitgutter_async', 1)
|
||||
let g:gitgutter_log = get(g:, 'gitgutter_log', 0)
|
||||
let g:gitgutter_use_location_list = get(g:, 'gitgutter_use_location_list', 0)
|
||||
let g:gitgutter_close_preview_on_escape = get(g:, 'gitgutter_close_preview_on_escape', 0)
|
||||
let g:gitgutter_show_msg_on_hunk_jumping = get(g:, 'gitgutter_show_msg_on_hunk_jumping', 1)
|
||||
|
||||
call s:set('g:gitgutter_git_executable', 'git')
|
||||
let g:gitgutter_git_executable = get(g:, 'gitgutter_git_executable', 'git')
|
||||
if !executable(g:gitgutter_git_executable)
|
||||
call gitgutter#utility#warn('cannot find git. Please set g:gitgutter_git_executable.')
|
||||
if g:gitgutter_enabled
|
||||
call gitgutter#utility#warn('cannot find git. Please set g:gitgutter_git_executable.')
|
||||
endif
|
||||
finish
|
||||
endif
|
||||
|
||||
let default_grep = 'grep'
|
||||
call s:set('g:gitgutter_grep', default_grep)
|
||||
let g:gitgutter_grep = get(g:, 'gitgutter_grep', default_grep)
|
||||
if !empty(g:gitgutter_grep)
|
||||
if executable(split(g:gitgutter_grep)[0])
|
||||
if $GREP_OPTIONS =~# '--color=always'
|
||||
@ -83,7 +91,6 @@ if !empty(g:gitgutter_grep)
|
||||
endif
|
||||
endif
|
||||
|
||||
call gitgutter#highlight#define_sign_column_highlight()
|
||||
call gitgutter#highlight#define_highlights()
|
||||
call gitgutter#highlight#define_signs()
|
||||
|
||||
@ -212,6 +219,21 @@ nnoremap <silent> <Plug>GitGutterPreviewHunk :call gitgutter#utility#warn('ple
|
||||
function! s:on_bufenter()
|
||||
call gitgutter#setup_maps()
|
||||
|
||||
" To keep vim's start-up fast, do not process the buffer when vim is starting.
|
||||
" Instead process it a short time later. Normally we would rely on our
|
||||
" CursorHold autocommand to handle this but it turns out CursorHold is not
|
||||
" guaranteed to fire if the user has not typed anything yet; so set up a
|
||||
" timer instead. The disadvantage is that if CursorHold does fire, the
|
||||
" plugin will do a round of unnecessary work; but since there will not have
|
||||
" been any changes to the buffer since the first round, the second round
|
||||
" will be cheap.
|
||||
if has('vim_starting') && !$VIM_GITGUTTER_TEST
|
||||
if exists('*timer_start')
|
||||
call timer_start(&updatetime, 'GitGutterCursorHold')
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
if exists('t:gitgutter_didtabenter') && t:gitgutter_didtabenter
|
||||
let t:gitgutter_didtabenter = 0
|
||||
call gitgutter#all(!g:gitgutter_terminal_reports_focus)
|
||||
@ -220,6 +242,10 @@ function! s:on_bufenter()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! GitGutterCursorHold(timer)
|
||||
execute 'doautocmd' s:nomodeline 'gitgutter CursorHold'
|
||||
endfunction
|
||||
|
||||
" Autocommands {{{
|
||||
|
||||
augroup gitgutter
|
||||
@ -229,6 +255,11 @@ augroup gitgutter
|
||||
|
||||
autocmd BufEnter * call s:on_bufenter()
|
||||
|
||||
" Ensure Vim is always checking for CursorMoved to avoid CursorMoved
|
||||
" being fired at the wrong time in floating preview window on Neovim.
|
||||
" See vim/vim#2053.
|
||||
autocmd CursorMoved * execute ''
|
||||
|
||||
autocmd CursorHold,CursorHoldI * call gitgutter#process_buffer(bufnr(''), 0)
|
||||
if exists('*timer_start') && has('lambda')
|
||||
autocmd FileChangedShellPost * call timer_start(1, {-> gitgutter#process_buffer(bufnr(''), 1)})
|
||||
@ -256,14 +287,14 @@ augroup gitgutter
|
||||
" FocusGained gets triggered on startup with Neovim at least already.
|
||||
" Therefore this tracks also if it was lost before.
|
||||
let s:focus_was_lost = 0
|
||||
autocmd FocusGained * if s:focus_was_lost | let focus_was_lost = 0 | call gitgutter#all(1) | endif
|
||||
autocmd FocusGained * if s:focus_was_lost | let s:focus_was_lost = 0 | call gitgutter#all(1) | endif
|
||||
autocmd FocusLost * let s:focus_was_lost = 1
|
||||
|
||||
if exists('##VimResume')
|
||||
autocmd VimResume * call gitgutter#all(1)
|
||||
endif
|
||||
|
||||
autocmd ColorScheme * call gitgutter#highlight#define_sign_column_highlight() | call gitgutter#highlight#define_highlights()
|
||||
autocmd ColorScheme * call gitgutter#highlight#define_highlights()
|
||||
|
||||
" Disable during :vimgrep
|
||||
autocmd QuickFixCmdPre *vimgrep* let g:gitgutter_enabled = 0
|
||||
|
@ -1,27 +0,0 @@
|
||||
" Measure how long it takes to unplace signs.
|
||||
"
|
||||
" Source this file with `:source %` or `vim -S unplace.vim`
|
||||
|
||||
|
||||
let num = 500
|
||||
sign define Foo text=*
|
||||
|
||||
new
|
||||
|
||||
call append(0, range(1, num))
|
||||
|
||||
for i in range(1, num)
|
||||
execute "sign place ".i." line=".i." name=Foo buffer=".bufnr('')
|
||||
endfor
|
||||
|
||||
let start = reltime()
|
||||
for i in range(1, num)
|
||||
execute "sign unplace ".i
|
||||
endfor
|
||||
let elapsed = reltime(start)
|
||||
|
||||
bdelete!
|
||||
|
||||
echom split(reltimestr(elapsed))[0]."s to remove ".num." signs"
|
||||
echom string(reltimefloat(elapsed) * 1000 / num).' ms/sign'
|
||||
echom string(float2nr(num / reltimefloat(elapsed))).' sign/s'
|
Reference in New Issue
Block a user