1
0
mirror of https://github.com/amix/vimrc synced 2025-07-13 14:55:01 +08:00

Merge branch 'Linux' of https://github.com/Geezus42/vimrc into Linux

This commit is contained in:
geezus
2021-06-30 13:19:18 -05:00
235 changed files with 6246 additions and 1351 deletions

View File

@ -77,13 +77,16 @@ nvim -u NONE -c "helptags vim-gitgutter/doc" -c q
### Windows
I recommend configuring vim-gitgutter with the full path to your git executable. For example:
There is a potential risk on Windows due to `cmd.exe` prioritising the current folder over folders in `PATH`. If you have a file named `git.*` (i.e. with any extension in `PATHEXT`) in your current folder, it will be executed instead of git whenever the plugin calls git.
You can avoid this risk by configuring the full path to your git executable. For example:
```viml
" This path probably won't work
let g:gitgutter_git_executable = 'C:\Program Files\Git\bin\git.exe'
```
This is to avoid a problem which occurs if you have file named `git.*` (i.e. with any extension in `PATHEXT`) in your current folder. `cmd.exe` prioritises the current folder over folders in `PATH` and will try to execute your file instead of the `git` binary.
Unfortunately I don't know the correct escaping for the path - if you do, please let me know!
### Getting started
@ -685,8 +688,6 @@ If this plugin has helped you, or you'd like to learn more about Vim, why not ch
This was one of PeepCode's all-time top three bestsellers and is now available at Pluralsight.
You can read reviews on my [website][airblade].
### Intellectual Property

View File

@ -70,7 +70,7 @@ let s:counter = 0
" grep is available.
function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
if gitgutter#utility#repo_path(a:bufnr, 0) == -1
throw 'gitgutter author fail'
throw 'gitgutter path not set'
endif
if gitgutter#utility#repo_path(a:bufnr, 0) == -2

View File

@ -64,6 +64,9 @@ function! gitgutter#hunk#next_hunk(count) abort
if g:gitgutter_show_msg_on_hunk_jumping
redraw | echo printf('Hunk %d of %d', index(hunks, hunk) + 1, len(hunks))
endif
if gitgutter#hunk#is_preview_window_open()
call gitgutter#hunk#preview()
endif
return
endif
endif
@ -92,6 +95,9 @@ function! gitgutter#hunk#prev_hunk(count) abort
if g:gitgutter_show_msg_on_hunk_jumping
redraw | echo printf('Hunk %d of %d', index(hunks, hunk) + 1, len(hunks))
endif
if gitgutter#hunk#is_preview_window_open()
call gitgutter#hunk#preview()
endif
return
endif
endif
@ -243,7 +249,7 @@ function! s:hunk_op(op, ...)
let hunk_diff = join(hunk_header + hunk_body, "\n")."\n"
call s:goto_original_window()
call s:close_hunk_preview_window()
call gitgutter#hunk#close_hunk_preview_window()
call s:stage(hunk_diff)
endif
@ -260,7 +266,7 @@ function! s:hunk_op(op, ...)
call gitgutter#diff#process_hunks(bufnr, gitgutter#hunk#hunks(bufnr)) " so the hunk summary is updated
if empty(s:current_hunk())
call gitgutter#utility#warn('cursor is not in a hunk')
call gitgutter#utility#warn('Cursor is not in a hunk')
elseif s:cursor_in_two_hunks()
let choice = input('Choose hunk: upper or lower (u/l)? ')
" Clear input
@ -270,7 +276,7 @@ function! s:hunk_op(op, ...)
elseif choice =~ 'l'
call a:op(gitgutter#diff#hunk_diff(bufnr, diff, 1))
else
call gitgutter#utility#warn('did not recognise your choice')
call gitgutter#utility#warn('Did not recognise your choice')
endif
else
let hunk_diff = gitgutter#diff#hunk_diff(bufnr, diff)
@ -294,7 +300,7 @@ function! s:stage(hunk_diff)
\ gitgutter#utility#cd_cmd(bufnr, g:gitgutter_git_executable.' '.g:gitgutter_git_args.' apply --cached --unidiff-zero - '),
\ diff)
if v:shell_error
call gitgutter#utility#warn('patch does not apply')
call gitgutter#utility#warn('Patch does not apply')
else
if exists('#User#GitGutterStage')
execute 'doautocmd' s:nomodeline 'User GitGutterStage'
@ -421,7 +427,7 @@ endfunction
function! s:open_hunk_preview_window()
if g:gitgutter_preview_win_floating
if exists('*nvim_open_win')
call s:close_hunk_preview_window()
call gitgutter#hunk#close_hunk_preview_window()
let buf = nvim_create_buf(v:false, v:false)
" Set default width and height for now.
@ -440,9 +446,21 @@ function! s:open_hunk_preview_window()
call nvim_buf_set_name(buf, 'gitgutter://hunk-preview')
" Assumes cursor is in original window.
<<<<<<< HEAD
autocmd CursorMoved <buffer> ++once call s:close_hunk_preview_window()
if g:gitgutter_close_preview_on_escape
nnoremap <buffer> <silent> <Esc> :call <SID>close_hunk_preview_window()<CR>
=======
autocmd CursorMoved <buffer> ++once call gitgutter#hunk#close_hunk_preview_window()
if g:gitgutter_close_preview_on_escape
" Map <Esc> to close the floating preview.
nnoremap <buffer> <silent> <Esc> :<C-U>call gitgutter#hunk#close_hunk_preview_window()<CR>
" Ensure that when the preview window is closed, the map is removed.
autocmd User GitGutterPreviewClosed silent! nunmap <buffer> <Esc>
autocmd CursorMoved <buffer> ++once silent! nunmap <buffer> <Esc>
execute "autocmd WinClosed <buffer=".winbufnr(s:winid)."> doautocmd" s:nomodeline "User GitGutterPreviewClosed"
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
endif
return
@ -466,7 +484,11 @@ function! s:open_hunk_preview_window()
endif
endif
" Specifying where to open the preview window can lead to the cursor going
" to an unexpected window when the preview window is closed (#769).
silent! noautocmd execute g:gitgutter_preview_win_location 'pedit gitgutter://hunk-preview'
silent! wincmd P
<<<<<<< HEAD
if &previewwindow
file gitgutter://hunk-preview
else
@ -475,6 +497,10 @@ function! s:open_hunk_preview_window()
doautocmd WinEnter
set previewwindow
endif
=======
setlocal statusline=%{''}
doautocmd WinEnter
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
if exists('*win_getid')
let s:winid = win_getid()
else
@ -484,7 +510,8 @@ function! s:open_hunk_preview_window()
" 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>
" Ensure cursor goes to the expected window.
nnoremap <buffer> <silent> <Esc> :<C-U>wincmd p<Bar>pclose<CR>
endif
endfunction
@ -498,6 +525,15 @@ function! s:close_popup_on_escape(winid, key)
endfunction
function! s:close_popup_on_escape(winid, key)
if a:key == "\<Esc>"
call popup_close(a:winid)
return 1
endif
return 0
endfunction
" Floating window: does not care where cursor is.
" Preview window: assumes cursor is in preview window.
function! s:populate_hunk_preview_window(header, body)
@ -549,7 +585,8 @@ function! s:populate_hunk_preview_window(header, body)
setlocal nomodified
normal! G$
let height = min([winline(), &previewheight])
let hunk_height = max([body_length, winline()])
let height = min([hunk_height, &previewheight])
execute 'resize' height
1
@ -579,7 +616,7 @@ function! s:goto_original_window()
endfunction
function! s:close_hunk_preview_window()
function! gitgutter#hunk#close_hunk_preview_window()
let bufnr = s:winid != 0 ? winbufnr(s:winid) : s:preview_bufnr
call setbufvar(bufnr, '&modified', 0)
@ -594,3 +631,19 @@ function! s:close_hunk_preview_window()
let s:winid = 0
let s:preview_bufnr = 0
endfunction
function gitgutter#hunk#is_preview_window_open()
if g:gitgutter_preview_win_floating
if win_id2win(s:winid) > 0
execute win_id2win(s:winid).'wincmd c'
endif
else
for i in range(1, winnr('$'))
if getwinvar(i, '&previewwindow')
return 1
endif
endfor
endif
return 0
endfunction

View File

@ -30,7 +30,7 @@ endfunction
function! gitgutter#utility#warn(message) abort
echohl WarningMsg
echo 'vim-gitgutter: ' . a:message
echo a:message
echohl None
let v:warningmsg = a:message
endfunction
@ -39,7 +39,7 @@ function! gitgutter#utility#warn_once(bufnr, message, key) abort
if empty(gitgutter#utility#getbufvar(a:bufnr, a:key))
call gitgutter#utility#setbufvar(a:bufnr, a:key, '1')
echohl WarningMsg
redraw | echom 'vim-gitgutter: ' . a:message
redraw | echom a:message
echohl None
let v:warningmsg = a:message
endif

View File

@ -63,15 +63,20 @@ Neovim:~
===============================================================================
WINDOWS *gitgutter-windows*
I recommend configuring vim-gitgutter with the full path to your git executable.
There is a potential risk on Windows due to `cmd.exe` prioritising the current
folder over folders in `PATH`. If you have a file named `git.*` (i.e. with
any extension in `PATHEXT`) in your current folder, it will be executed
instead of git whenever the plugin calls git.
You can avoid this risk by configuring the full path to your git executable.
For example:
>
" This path probably won't work
let g:gitgutter_git_executable = 'C:\Program Files\Git\bin\git.exe'
<
This is to avoid a problem which occurs if you have file named "git.*" (i.e.
with any extension in "PATHEXT") in your current folder. "cmd.exe" prioritises
the current folder over folders in 'PATH' and will try to execute your file
instead of the "git" binary.
Unfortunately I don't know the correct escaping for the path - if you do,
please let me know!
===============================================================================
@ -172,14 +177,36 @@ Commands for operating on a hunk:~
*gitgutter-:GitGutterPreviewHunk*
:GitGutterPreviewHunk Preview the hunk the cursor is in.
<<<<<<< HEAD
Use |:pclose| or |CTRL-W_CTRL-Z| to close the preview
window, or set |g:gitgutter_close_preview_on_escape|
and use <Esc>.
=======
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
To stage part of the hunk, move to the preview window,
delete any lines you do not want to stage, and
|GitGutterStageHunk|.
To close a non-floating preview window use |:pclose|
or |CTRL-W_z| or |CTRL-W_CTRL-Z|; or normal window-
closing (|:quit| or |:close| or |CTRL-W_c|) if your cursor
is in the preview window.
To close a floating window when the cursor is in the
original buffer, move the cursor.
To close a floating window when the cursor is in the
floating window use normal window-closing, or move to
the original window with |CTRL-W_p|. Alternatively set
|g:gitgutter_close_preview_on_escape| and use <Esc>.
Two functions are available for your own logic:
>
gitgutter#hunk#is_preview_window_open()
gitgutter#hunk#close_hunk_preview_window()
<
Commands for folds:~
*gitgutter-:GitGutterFold*

View File

@ -8,7 +8,7 @@ let g:loaded_gitgutter = 1
" Initialisation {{{
if v:version < 703 || (v:version == 703 && !has("patch105"))
call gitgutter#utility#warn('requires Vim 7.3.105')
call gitgutter#utility#warn('Requires Vim 7.3.105')
finish
endif
@ -25,7 +25,8 @@ let g:gitgutter_preview_win_location = get(g:, 'gitgutter_preview_win_location',
if exists('*nvim_open_win')
let g:gitgutter_preview_win_floating = get(g:, 'gitgutter_preview_win_floating', 1)
else
let g:gitgutter_preview_win_floating = get(g:, 'gitgutter_preview_win_floating', 0)
let default = exists('&previewpopup') ? !empty(&previewpopup) : 0
let g:gitgutter_preview_win_floating = get(g:, 'gitgutter_preview_win_floating', default)
endif
let g:gitgutter_enabled = get(g:, 'gitgutter_enabled', 1)
if exists('*sign_unplace')
@ -71,7 +72,7 @@ let g:gitgutter_show_msg_on_hunk_jumping = get(g:, 'gitgutter_show_msg_on_hu
let g:gitgutter_git_executable = get(g:, 'gitgutter_git_executable', 'git')
if !executable(g:gitgutter_git_executable)
if g:gitgutter_enabled
call gitgutter#utility#warn('cannot find git. Please set g:gitgutter_git_executable.')
call gitgutter#utility#warn('Cannot find git. Please set g:gitgutter_git_executable.')
endif
finish
endif
@ -85,7 +86,7 @@ if !empty(g:gitgutter_grep)
endif
else
if g:gitgutter_grep !=# default_grep
call gitgutter#utility#warn('cannot find '.g:gitgutter_grep.'. Please check g:gitgutter_grep.')
call gitgutter#utility#warn('Cannot find '.g:gitgutter_grep.'. Please check g:gitgutter_grep.')
endif
let g:gitgutter_grep = ''
endif
@ -202,18 +203,18 @@ command! -bar GitGutterDebug call gitgutter#debug#debug()
" Maps {{{
nnoremap <silent> <expr> <Plug>(GitGutterNextHunk) &diff ? ']c' : ":\<C-U>execute v:count1 . 'GitGutterNextHunk'\<CR>"
nnoremap <silent> <expr> <Plug>GitGutterNextHunk &diff ? ']c' : ":\<C-U>call gitgutter#utility#warn('please change your map \<lt>Plug>GitGutterNextHunk to \<lt>Plug>(GitGutterNextHunk)')\<CR>"
nnoremap <silent> <expr> <Plug>GitGutterNextHunk &diff ? ']c' : ":\<C-U>call gitgutter#utility#warn('Please change your map \<lt>Plug>GitGutterNextHunk to \<lt>Plug>(GitGutterNextHunk)')\<CR>"
nnoremap <silent> <expr> <Plug>(GitGutterPrevHunk) &diff ? '[c' : ":\<C-U>execute v:count1 . 'GitGutterPrevHunk'\<CR>"
nnoremap <silent> <expr> <Plug>GitGutterPrevHunk &diff ? '[c' : ":\<C-U>call gitgutter#utility#warn('please change your map \<lt>Plug>GitGutterPrevHunk to \<lt>Plug>(GitGutterPrevHunk)')\<CR>"
nnoremap <silent> <expr> <Plug>GitGutterPrevHunk &diff ? '[c' : ":\<C-U>call gitgutter#utility#warn('Please change your map \<lt>Plug>GitGutterPrevHunk to \<lt>Plug>(GitGutterPrevHunk)')\<CR>"
xnoremap <silent> <Plug>(GitGutterStageHunk) :GitGutterStageHunk<CR>
xnoremap <silent> <Plug>GitGutterStageHunk :call gitgutter#utility#warn('please change your map <lt>Plug>GitGutterStageHunk to <lt>Plug>(GitGutterStageHunk)')<CR>
xnoremap <silent> <Plug>GitGutterStageHunk :call gitgutter#utility#warn('Please change your map <lt>Plug>GitGutterStageHunk to <lt>Plug>(GitGutterStageHunk)')<CR>
nnoremap <silent> <Plug>(GitGutterStageHunk) :GitGutterStageHunk<CR>
nnoremap <silent> <Plug>GitGutterStageHunk :call gitgutter#utility#warn('please change your map <lt>Plug>GitGutterStageHunk to <lt>Plug>(GitGutterStageHunk)')<CR>
nnoremap <silent> <Plug>GitGutterStageHunk :call gitgutter#utility#warn('Please change your map <lt>Plug>GitGutterStageHunk to <lt>Plug>(GitGutterStageHunk)')<CR>
nnoremap <silent> <Plug>(GitGutterUndoHunk) :GitGutterUndoHunk<CR>
nnoremap <silent> <Plug>GitGutterUndoHunk :call gitgutter#utility#warn('please change your map <lt>Plug>GitGutterUndoHunk to <lt>Plug>(GitGutterUndoHunk)')<CR>
nnoremap <silent> <Plug>GitGutterUndoHunk :call gitgutter#utility#warn('Please change your map <lt>Plug>GitGutterUndoHunk to <lt>Plug>(GitGutterUndoHunk)')<CR>
nnoremap <silent> <Plug>(GitGutterPreviewHunk) :GitGutterPreviewHunk<CR>
nnoremap <silent> <Plug>GitGutterPreviewHunk :call gitgutter#utility#warn('please change your map <lt>Plug>GitGutterPreviewHunk to <lt>Plug>(GitGutterPreviewHunk)')<CR>
nnoremap <silent> <Plug>GitGutterPreviewHunk :call gitgutter#utility#warn('Please change your map <lt>Plug>GitGutterPreviewHunk to <lt>Plug>(GitGutterPreviewHunk)')<CR>
" }}}