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

Updated plugins

This commit is contained in:
Amir
2023-07-15 12:43:27 +02:00
parent 68cf3c02e2
commit 747d4093f4
52 changed files with 767 additions and 165 deletions

View File

@ -23,6 +23,7 @@ Features:
* Provides fold text showing whether folded lines have been changed.
* Can load all hunk locations into quickfix list or the current window's location list.
* Handles line endings correctly, even with repos that do CRLF conversion.
* Handles clean/smudge filters.
* Optional line highlighting.
* 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).
@ -54,7 +55,7 @@ In the screenshot above you can see:
### Installation
Install using your favourite package manager, or use Vim's built-in package support.
First, install using your favourite package manager, or use Vim's built-in package support.
Vim:
@ -67,7 +68,6 @@ vim -u NONE -c "helptags vim-gitgutter/doc" -c q
Neovim:
```
mkdir -p ~/.config/nvim/pack/airblade/start
cd ~/.config/nvim/pack/airblade/start
@ -75,6 +75,12 @@ git clone https://github.com/airblade/vim-gitgutter.git
nvim -u NONE -c "helptags vim-gitgutter/doc" -c q
```
Second, ensure your `updatetime` and `signcolumn` options are set appropriately.
When you make a change to a file tracked by git, the diff markers should appear automatically after a short delay. The delay is governed by vim's `updatetime` option; the default value is `4000`, i.e. 4 seconds, but I suggest reducing it to around 100ms (add `set updatetime=100` to your vimrc). Note `updatetime` also controls the delay before vim writes its swap file (see `:help updatetime`).
The `signcolumn` option can have any value except `'off'`.
### Windows
@ -92,7 +98,7 @@ Unfortunately I don't know the correct escaping for the path - if you do, please
### Getting started
When you make a change to a file tracked by git, the diff markers should appear automatically. The delay is governed by vim's `updatetime` option; the default value is `4000`, i.e. 4 seconds, but I suggest reducing it to around 100ms (add `set updatetime=100` to your vimrc). Note `updatetime` also controls the delay before vim writes its swap file (see `:help updatetime`).
When you make a change to a file tracked by git, the diff markers should appear automatically after a short delay.
You can jump between hunks with `[c` and `]c`. You can preview, stage, and undo hunks with `<leader>hp`, `<leader>hs`, and `<leader>hu` respectively.
@ -375,7 +381,7 @@ Similarly to the signs' colours, set up the following highlight groups in your c
GitGutterAddLine " default: links to DiffAdd
GitGutterChangeLine " default: links to DiffChange
GitGutterDeleteLine " default: links to DiffDelete
GitGutterChangeDeleteLine " default: links to GitGutterChangeLineDefault, i.e. DiffChange
GitGutterChangeDeleteLine " default: links to GitGutterChangeLine, i.e. DiffChange
```
For example, in some colorschemes the `DiffText` highlight group is easier to read than `DiffChange`. You could use it like this:
@ -395,7 +401,7 @@ Similarly to the signs' colours, set up the following highlight groups in your c
GitGutterAddLineNr " default: links to CursorLineNr
GitGutterChangeLineNr " default: links to CursorLineNr
GitGutterDeleteLineNr " default: links to CursorLineNr
GitGutterChangeDeleteLineNr " default: links to CursorLineNr
GitGutterChangeDeleteLineNr " default: links to GitGutterChangeLineNr
```
Maybe you think `CursorLineNr` is a bit annoying. For example, you could use `Underlined` for this:
@ -747,5 +753,4 @@ Copyright Andrew Stewart, AirBlade Software Ltd. Released under the MIT licence
[pathogen]: https://github.com/tpope/vim-pathogen
[siv]: http://pluralsight.com/training/Courses/TableOfContents/smash-into-vim
[airblade]: http://airbladesoftware.com/peepcode-vim
[terminus]: https://github.com/wincent/terminus

View File

@ -46,6 +46,8 @@ function! gitgutter#process_buffer(bufnr, force) abort
call gitgutter#debug#log('Not tracked: '.gitgutter#utility#file(a:bufnr))
catch /gitgutter assume unchanged/
call gitgutter#debug#log('Assume unchanged: '.gitgutter#utility#file(a:bufnr))
catch /gitgutter file unknown in base/
let diff = gitgutter#diff#hunk_header_showing_every_line_added(a:bufnr)
catch /gitgutter diff failed/
call gitgutter#debug#log('Diff failed: '.gitgutter#utility#file(a:bufnr))
call gitgutter#hunk#reset(a:bufnr)
@ -117,6 +119,16 @@ endfunction
" }}}
function! gitgutter#git()
if empty(g:gitgutter_git_args)
return g:gitgutter_git_executable
else
return g:gitgutter_git_executable.' '.g:gitgutter_git_args
endif
endfunction
function! gitgutter#setup_maps()
if !g:gitgutter_map_keys
return
@ -193,14 +205,14 @@ endfunction
" - it ignores unsaved changes in buffers
" - it does not change to the repo root
function! gitgutter#quickfix(current_file)
let cmd = g:gitgutter_git_executable.' '.g:gitgutter_git_args.' rev-parse --show-cdup'
let cmd = gitgutter#git().' 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'.
let cmd = gitgutter#git().' --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
@ -249,7 +261,7 @@ function! gitgutter#difforig()
if g:gitgutter_diff_relative_to ==# 'index'
let index_name = gitgutter#utility#get_diff_base(bufnr).':'.path
let cmd = gitgutter#utility#cd_cmd(bufnr,
\ g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager show '.index_name
\ gitgutter#git().' --no-pager show '.index_name
\ )
" NOTE: this uses &shell to execute cmd. Perhaps we should use instead
" gitgutter#utility's use_known_shell() / restore_shell() functions.

View File

@ -75,23 +75,21 @@ function! gitgutter#debug#log(message, ...) abort
endif
endif
execute 'redir >> '.s:log_file
if s:new_log_session
let s:start = reltime()
silent echo "\n==== start log session ===="
endif
if s:new_log_session
let s:start = reltime()
call writefile(['', '========== start log session '.strftime('%d.%m.%Y %H:%M:%S').' =========='], s:log_file, 'a')
endif
let elapsed = reltimestr(reltime(s:start)).' '
silent echo ''
" callers excluding this function
silent echo elapsed.expand('<sfile>')[:-22].':'
silent echo elapsed.s:format_for_log(a:message)
if a:0 && !empty(a:1)
for msg in a:000
silent echo elapsed.s:format_for_log(msg)
endfor
endif
redir END
let elapsed = reltimestr(reltime(s:start)).' '
call writefile([''], s:log_file, 'a')
" callers excluding this function
call writefile([elapsed.expand('<sfile>')[:-22].':'], s:log_file, 'a')
call writefile([elapsed.s:format_for_log(a:message)], s:log_file, 'a')
if a:0 && !empty(a:1)
for msg in a:000
call writefile([elapsed.s:format_for_log(msg)], s:log_file, 'a')
endfor
endif
let s:new_log_session = 0
endif

View File

@ -6,7 +6,7 @@ let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
" True for git v1.7.2+.
function! s:git_supports_command_line_config_override() abort
call gitgutter#utility#system(g:gitgutter_git_executable.' '.g:gitgutter_git_args.' -c foo.bar=baz --version')
call gitgutter#utility#system(gitgutter#git().' -c foo.bar=baz --version')
return !v:shell_error
endfunction
@ -81,6 +81,20 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
throw 'gitgutter assume unchanged'
endif
" If we are diffing against a specific branch/commit, handle the case
" where a file exists on the current branch but not in/at the diff base.
" We have to handle it here because the approach below (using git-show)
" doesn't work for this case.
if !empty(g:gitgutter_diff_base)
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#repo_path(a:bufnr, 1)
let cmd = gitgutter#git().' --no-pager show '.index_name
let cmd = gitgutter#utility#cd_cmd(a:bufnr, cmd)
call gitgutter#utility#system(cmd)
if v:shell_error
throw 'gitgutter file unknown in base'
endif
endif
" Wrap compound commands in parentheses to make Windows happy.
" bash doesn't mind the parentheses.
let cmd = '('
@ -124,14 +138,14 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
" Write file from index to temporary file.
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.' && '
let cmd .= gitgutter#git().' --no-pager show --textconv '.index_name.' > '.from_file.' && '
elseif a:from ==# 'working_tree'
let from_file = gitgutter#utility#repo_path(a:bufnr, 1)
endif
" Call git-diff.
let cmd .= g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager'
let cmd .= gitgutter#git().' --no-pager'
if s:c_flag
let cmd .= ' -c "diff.autorefreshindex=0"'
let cmd .= ' -c "diff.noprefix=false"'
@ -376,6 +390,12 @@ function! gitgutter#diff#hunk_diff(bufnr, full_diff, ...)
endfunction
function! gitgutter#diff#hunk_header_showing_every_line_added(bufnr)
let buf_line_count = getbufinfo(a:bufnr)[0].linecount
return '@@ -0,0 +1,'.buf_line_count.' @@'
endfunction
function! s:write_buffer(bufnr, file)
let bufcontents = getbufline(a:bufnr, 1, '$')
@ -387,7 +407,13 @@ function! s:write_buffer(bufnr, file)
endif
if getbufvar(a:bufnr, '&fileformat') ==# 'dos'
call map(bufcontents, 'v:val."\r"')
if getbufvar(a:bufnr, '&endofline')
call map(bufcontents, 'v:val."\r"')
else
for i in range(len(bufcontents) - 1)
let bufcontents[i] = bufcontents[i] . "\r"
endfor
endif
endif
if getbufvar(a:bufnr, '&endofline')

View File

@ -106,7 +106,7 @@ function! gitgutter#highlight#define_highlights() abort
highlight default link GitGutterAddLineNr CursorLineNr
highlight default link GitGutterChangeLineNr CursorLineNr
highlight default link GitGutterDeleteLineNr CursorLineNr
highlight default link GitGutterChangeDeleteLineNr CursorLineNr
highlight default link GitGutterChangeDeleteLineNr GitGutterChangeLineNr
" Highlights used intra line.
highlight default GitGutterAddIntraLine gui=reverse cterm=reverse

View File

@ -294,11 +294,32 @@ endfunction
function! s:stage(hunk_diff)
let bufnr = bufnr('')
let diff = s:adjust_header(bufnr, a:hunk_diff)
" Apply patch to index.
call gitgutter#utility#system(
\ gitgutter#utility#cd_cmd(bufnr, g:gitgutter_git_executable.' '.g:gitgutter_git_args.' apply --cached --unidiff-zero - '),
\ diff)
if gitgutter#utility#clean_smudge_filter_applies(bufnr)
let choice = input('File uses clean/smudge filter. Stage entire file (y/n)? ')
normal! :<ESC>
if choice =~ 'y'
" We are about to add the file to the index so write the buffer to
" ensure the file on disk matches it (the buffer).
write
let path = gitgutter#utility#repo_path(bufnr, 1)
" Add file to index.
let cmd = gitgutter#utility#cd_cmd(bufnr,
\ gitgutter#git().' add '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(bufnr)))
call gitgutter#utility#system(cmd)
else
return
endif
else
let diff = s:adjust_header(bufnr, a:hunk_diff)
" Apply patch to index.
call gitgutter#utility#system(
\ gitgutter#utility#cd_cmd(bufnr, gitgutter#git().' apply --cached --unidiff-zero - '),
\ diff)
endif
if v:shell_error
call gitgutter#utility#warn('Patch does not apply')
else
@ -422,6 +443,9 @@ endfunction
" Floating window: does not move cursor to floating window.
" Preview window: moves cursor to preview window.
function! s:open_hunk_preview_window()
let source_wrap = &wrap
let source_window = winnr()
if g:gitgutter_preview_win_floating
if exists('*nvim_open_win')
call gitgutter#hunk#close_hunk_preview_window()
@ -429,6 +453,7 @@ function! s:open_hunk_preview_window()
let buf = nvim_create_buf(v:false, v:false)
" Set default width and height for now.
let s:winid = nvim_open_win(buf, v:false, g:gitgutter_floating_window_options)
call nvim_win_set_option(s:winid, 'wrap', source_wrap ? v:true : v:false)
call nvim_buf_set_option(buf, 'filetype', 'diff')
call nvim_buf_set_option(buf, 'buftype', 'acwrite')
call nvim_buf_set_option(buf, 'bufhidden', 'delete')
@ -458,6 +483,7 @@ function! s:open_hunk_preview_window()
let s:winid = popup_create('', g:gitgutter_floating_window_options)
call setbufvar(winbufnr(s:winid), '&filetype', 'diff')
call setwinvar(s:winid, '&wrap', source_wrap)
return
endif
@ -479,11 +505,13 @@ function! s:open_hunk_preview_window()
let s:preview_bufnr = bufnr('')
endif
setlocal filetype=diff buftype=acwrite bufhidden=delete
let &l:wrap = source_wrap
let b:source_window = source_window
" Reset some defaults in case someone else has changed them.
setlocal noreadonly modifiable noswapfile
if g:gitgutter_close_preview_on_escape
" Ensure cursor goes to the expected window.
nnoremap <buffer> <silent> <Esc> :<C-U>wincmd p<Bar>pclose<CR>
nnoremap <buffer> <silent> <Esc> :<C-U>execute b:source_window . "wincmd w"<Bar>pclose<CR>
endif
if exists('&previewpopup')
@ -594,7 +622,7 @@ endfunction
function! s:goto_original_window()
noautocmd wincmd p
noautocmd execute b:source_window . "wincmd w"
doautocmd WinEnter
endfunction

View File

@ -150,9 +150,8 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
call gitgutter#utility#setbufvar(a:bufnr, 'path', -1)
let cmd = gitgutter#utility#cd_cmd(a:bufnr,
\ g:gitgutter_git_executable.' '.g:gitgutter_git_args.
\ ' ls-files -v --error-unmatch --full-name -z -- '.
\ gitgutter#utility#shellescape(s:filename(a:bufnr)))
\ gitgutter#git().' ls-files -v --error-unmatch --full-name -z -- '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(a:bufnr)))
if g:gitgutter_async && gitgutter#async#available() && !has('vim_starting')
let handler = copy(s:set_path_handler)
@ -178,6 +177,20 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
endfunction
function! gitgutter#utility#clean_smudge_filter_applies(bufnr)
let filtered = gitgutter#utility#getbufvar(a:bufnr, 'filter', -1)
if filtered == -1
let cmd = gitgutter#utility#cd_cmd(a:bufnr,
\ gitgutter#git().' check-attr filter -- '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(a:bufnr)))
let out = gitgutter#utility#system(cmd)
let filtered = out !~ 'unspecified'
call gitgutter#utility#setbufvar(a:bufnr, 'filter', filtered)
endif
return filtered
endfunction
function! gitgutter#utility#cd_cmd(bufnr, cmd) abort
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
@ -233,7 +246,7 @@ function! s:dir(bufnr) abort
endfunction
" Not shellescaped.
function! s:filename(bufnr) abort
function! gitgutter#utility#filename(bufnr) abort
return fnamemodify(s:abs_path(a:bufnr, 0), ':t')
endfunction

View File

@ -41,7 +41,8 @@ one in 2013.
===============================================================================
INSTALLATION *gitgutter-installation*
Use your favourite package manager, or use Vim's built-in package support.
First, use your favourite package manager, or use Vim's built-in package
support.
Vim:~
>
@ -59,6 +60,16 @@ Neovim:~
nvim -u NONE -c "helptags vim-gitgutter/doc" -c q
<
Second, ensure your 'updatetime' and 'signcolumn' options are set appropriately.
When you make a change to a file tracked by git, the diff markers should
appear automatically after a short delay. The delay is governed by vim's
'updatetime' option; the default value is `4000`, i.e. 4 seconds, but I
suggest reducing it to around 100ms (add `set updatetime=100` to your vimrc).
Note 'updatetime' also controls the delay before vim writes its swap file.
The 'signcolumn' option can have any value except "off".
===============================================================================
WINDOWS *gitgutter-windows*
@ -635,7 +646,7 @@ colorscheme or |vimrc|:
GitGutterAddLine " default: links to DiffAdd
GitGutterChangeLine " default: links to DiffChange
GitGutterDeleteLine " default: links to DiffDelete
GitGutterChangeDeleteLine " default: links to GitGutterChangeLineDefault
GitGutterChangeDeleteLine " default: links to GitGutterChangeLine
<
For example, to use |hl-DiffText| instead of |hl-DiffChange|:
@ -648,7 +659,7 @@ your colorscheme or |vimrc|:
GitGutterAddLineNr " default: links to CursorLineNr
GitGutterChangeLineNr " default: links to CursorLineNr
GitGutterDeleteLineNr " default: links to CursorLineNr
GitGutterChangeDeleteLineNr " default: links to CursorLineNr
GitGutterChangeDeleteLineNr " default: links to GitGutterChangeLineNr
<
For example, to use |hl-Underlined| instead of |hl-CursorLineNr|:
>

View File

@ -296,9 +296,6 @@ augroup gitgutter
autocmd User FugitiveChanged call gitgutter#all(1)
autocmd BufFilePre * GitGutterBufferDisable
autocmd BufFilePost * GitGutterBufferEnable
" Handle all buffers when focus is gained, but only after it was lost.
" FocusGained gets triggered on startup with Neovim at least already.
" Therefore this tracks also if it was lost before.
@ -312,9 +309,11 @@ augroup gitgutter
autocmd ColorScheme * call gitgutter#highlight#define_highlights()
" Disable during :vimgrep
autocmd QuickFixCmdPre *vimgrep* let [g:gitgutter_was_enabled, g:gitgutter_enabled] = [g:gitgutter_enabled, 0]
autocmd QuickFixCmdPost *vimgrep* let g:gitgutter_enabled = g:gitgutter_was_enabled | unlet g:gitgutter_was_enabled
autocmd BufFilePre * let b:gitgutter_was_enabled = gitgutter#utility#getbufvar(expand('<abuf>'), 'enabled') | GitGutterBufferDisable
autocmd BufFilePost * if b:gitgutter_was_enabled | GitGutterBufferEnable | endif | unlet b:gitgutter_was_enabled
autocmd QuickFixCmdPre *vimgrep* let b:gitgutter_was_enabled = gitgutter#utility#getbufvar(expand('<abuf>'), 'enabled') | GitGutterBufferDisable
autocmd QuickFixCmdPost *vimgrep* if b:gitgutter_was_enabled | GitGutterBufferEnable | endif | unlet b:gitgutter_was_enabled
augroup END
" }}}

View File

@ -0,0 +1 @@
*.foo filter=reverse diff=reverse

View File

@ -0,0 +1,6 @@
[filter "reverse"]
clean = "rev"
smudge = "rev"
[diff "reverse"]
textconv = "cat"

View File

@ -0,0 +1,4 @@
one
two
three
four

View File

@ -0,0 +1,7 @@
a
b
c
d
e
f
g

View File

@ -54,8 +54,12 @@ endfunction
function SetUp()
call system("git init ".s:test_repo.
\ " && cd ".s:test_repo.
\ " && cp ../.gitconfig .".
\ " && cp ../.gitattributes .".
\ " && cp ../fixture.foo .".
\ " && cp ../fixture.txt .".
\ " && cp ../fixture_dos.txt .".
\ " && cp ../fixture_dos_noeol.txt .".
\ " && git add . && git commit -m 'initial'".
\ " && git config diff.mnemonicPrefix false")
execute ':cd' s:test_repo
@ -348,6 +352,21 @@ function Test_untracked_file_square_brackets_within_repo()
endfunction
function Test_file_unknown_in_base()
let starting_branch = system('git branch --show-current')
let starting_branch = 'main'
call system('git checkout -b some-feature')
let tmp = 'file-on-this-branch-only.tmp'
call system('echo "hi" > '.tmp.' && git add '.tmp)
execute 'edit '.tmp
let g:gitgutter_diff_base = starting_branch
GitGutter
let expected = [{'lnum': 1, 'name': 'GitGutterLineAdded', 'group': 'gitgutter', 'priority': 10}]
call s:assert_signs(expected, tmp)
let g:gitgutter_diff_base = ''
endfunction
function Test_hunk_outside_noop()
5
GitGutterStageHunk
@ -390,6 +409,12 @@ function Test_preview_dos()
endfunction
function Test_dos_noeol()
edit! fixture_dos_noeol.txt
GitGutter
call s:assert_signs([], 'fixture_dos_noeol.txt')
endfunction
function Test_hunk_stage()
@ -752,7 +777,7 @@ endfunction
function Test_overlapping_hunk_op()
func Answer(char)
func! Answer(char)
call feedkeys(a:char."\<CR>")
endfunc
@ -1164,3 +1189,29 @@ function Test_assume_unchanged()
call s:trigger_gitgutter()
call s:assert_signs([], 'fixture.txt')
endfunction
function Test_clean_smudge_filter()
call system("git config --local include.path ../.gitconfig")
call system("rm fixture.foo && git checkout fixture.foo")
func! Answer(char)
call feedkeys(a:char."\<CR>")
endfunc
edit fixture.foo
call setline(2, ['A'])
call setline(4, ['B'])
call s:trigger_gitgutter()
normal! 2G
call timer_start(100, {-> Answer('y')} )
GitGutterStageHunk
call s:trigger_gitgutter()
let expected = [
\ {'lnum': 2, 'id': 23, 'name': 'GitGutterLineModified', 'priority': 10, 'group': 'gitgutter'},
\ {'lnum': 4, 'id': 24, 'name': 'GitGutterLineModified', 'priority': 10, 'group': 'gitgutter'}
\ ]
" call s:assert_signs(expected, 'fixture.foo')
call s:assert_signs([], 'fixture.foo')
endfunction