1
0
mirror of https://github.com/amix/vimrc synced 2025-06-23 06:35:01 +08:00

Updated plugins

This commit is contained in:
Amir
2020-04-25 21:56:16 -04:00
parent d98c510eee
commit fef069af24
114 changed files with 4018 additions and 988 deletions

View File

@ -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
@ -308,31 +318,20 @@ 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 those for the signs' colours.
The signs' background colours will all be set to the sign column's background colour.
Otherwise it will use your colourscheme's `Diff*` highlight groups.
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:
Either way the signs' background colours will be set to the sign column's background colour.
If you don't like the colours, specify the ones you want in your vimrc (see `:help highlight-guifg` and `:help highlight-ctermfg`). For example, to get vim-gitgutter's original colours (based on git-diff's colours in my terminal):
```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)
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`.
To get vim-gitgutter's original colours (based on git-diff's colours in my terminal):
```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>
```
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
@ -399,6 +398,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 +633,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.

View File

@ -1,5 +1,3 @@
let s:t_string = type('')
" Primary functions {{{
function! gitgutter#all(force) abort
@ -37,7 +35,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/
@ -47,7 +45,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
@ -156,11 +154,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
return gitgutter#utility#set_repo_path(a:bufnr, a:continuation)
endfunction
@ -188,7 +182,7 @@ endfunction
function! gitgutter#quickfix()
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
\ ' diff --no-ext-diff --no-color -U0 '.g:gitgutter_diff_args. ' '. g:gitgutter_diff_base
let diff = systemlist(cmd)
let lnum = 0
for line in diff

View File

@ -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*\) @@'
@ -10,9 +12,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
" Returns a diff of the buffer against the index or the working tree.
@ -76,6 +75,9 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
throw 'gitgutter not tracked'
endif
let temp_from = tempname()
let temp_buffer = tempname()
" Wrap compound commands in parentheses to make Windows happy.
" bash doesn't mind the parentheses.
let cmd = '('
@ -88,7 +90,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
" second gitgutter#process_buffer() writing the file (synchronously, below)
" and the first gitgutter#process_buffer()'s async job reading it (with
" git-diff).
let buff_file = s:temp_buffer.'.'.a:bufnr
let buff_file = temp_buffer.'.'.a:bufnr
" Add a counter to avoid a similar race with two quick writes of the same buffer.
" Use a modulus greater than a maximum reasonable number of visible buffers.
@ -108,7 +110,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
" Without the buffer number, from_file would have a race in the shell
" between the second process writing it (with git-show) and the first
" reading it (with git-diff).
let from_file = s:temp_from.'.'.a:bufnr
let from_file = temp_from.'.'.a:bufnr
" Add a counter to avoid a similar race with two quick writes of the same buffer.
let from_file .= '.'.s:counter
@ -118,7 +120,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'
@ -405,5 +407,3 @@ endfunction
function! s:save_last_seen_change(bufnr) abort
call gitgutter#utility#setbufvar(a:bufnr, 'tick', getbufvar(a:bufnr, 'changedtick'))
endfunction

View File

@ -84,6 +84,20 @@ function! gitgutter#highlight#define_highlights() abort
highlight default link GitGutterChangeDeleteInvisible GitGutterChangeInvisible
" When they are visible.
" If GitGutter* highlights are already defined, either by the user or the colourscheme,
" set their backgrounds to the sign column's.
for type in ["Add", "Change", "Delete"]
if hlexists("GitGutter".type)
" Were the highlight self-contained we could just declare the
" background attributes and they would be merged. But it might be a
" link, in which case it would be overwritten. So re-declare it in its
" entirety.
let [guifg, ctermfg] = s:get_foreground_colors('GitGutter'.type)
execute "highlight GitGutter".type." guifg=".guifg." guibg=".guibg." ctermfg=".ctermfg." ctermbg=".ctermbg
endif
endfor
" 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)
@ -107,6 +121,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

View File

@ -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)
@ -172,6 +174,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 +185,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 +276,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.
@ -430,7 +442,12 @@ function! s:open_hunk_preview_window()
silent! wincmd P
if !&previewwindow
noautocmd execute g:gitgutter_preview_win_location &previewheight 'new gitgutter://hunk-preview'
let s:winid = win_getid()
doautocmd WinEnter
if exists('*win_getid')
let s:winid = win_getid()
else
let s:preview_bufnr = bufnr('')
endif
set previewwindow
setlocal filetype=diff buftype=acwrite bufhidden=delete
" Reset some defaults in case someone else has changed them.
@ -499,18 +516,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 +541,5 @@ function! s:close_hunk_preview_window()
endif
let s:winid = 0
let s:preview_bufnr = 0
endfunction

View File

@ -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
@ -186,8 +184,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

View File

@ -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*
@ -177,7 +180,7 @@ Commands for folds:~
===============================================================================
AUTOCOMMAND *gitgutter-autocommand*
AUTOCOMMANDS *gitgutter-autocommands*
User GitGutter~
@ -189,6 +192,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*
@ -366,6 +373,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|).
@ -519,20 +529,14 @@ of the current window instead of the global quickfix list.
===============================================================================
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.
To change the line highlights, set up the following highlight groups in your
colorscheme or |vimrc|: