mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-06 20:54:28 +08:00
[[B]Commits] Allow tracking changes in the line range
Thanks to @anhpt379 Close #898 Close #1288
This commit is contained in:
50
README.md
50
README.md
@@ -61,31 +61,31 @@ so you can omit it if you use a plugin manager that doesn't support hooks.
|
|||||||
Commands
|
Commands
|
||||||
--------
|
--------
|
||||||
|
|
||||||
| Command | List |
|
| Command | List |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `:Files [PATH]` | Files (runs `$FZF_DEFAULT_COMMAND` if defined) |
|
| `:Files [PATH]` | Files (runs `$FZF_DEFAULT_COMMAND` if defined) |
|
||||||
| `:GFiles [OPTS]` | Git files (`git ls-files`) |
|
| `:GFiles [OPTS]` | Git files (`git ls-files`) |
|
||||||
| `:GFiles?` | Git files (`git status`) |
|
| `:GFiles?` | Git files (`git status`) |
|
||||||
| `:Buffers` | Open buffers |
|
| `:Buffers` | Open buffers |
|
||||||
| `:Colors` | Color schemes |
|
| `:Colors` | Color schemes |
|
||||||
| `:Ag [PATTERN]` | [ag][ag] search result (`ALT-A` to select all, `ALT-D` to deselect all) |
|
| `:Ag [PATTERN]` | [ag][ag] search result (`ALT-A` to select all, `ALT-D` to deselect all) |
|
||||||
| `:Rg [PATTERN]` | [rg][rg] search result (`ALT-A` to select all, `ALT-D` to deselect all) |
|
| `:Rg [PATTERN]` | [rg][rg] search result (`ALT-A` to select all, `ALT-D` to deselect all) |
|
||||||
| `:Lines [QUERY]` | Lines in loaded buffers |
|
| `:Lines [QUERY]` | Lines in loaded buffers |
|
||||||
| `:BLines [QUERY]` | Lines in the current buffer |
|
| `:BLines [QUERY]` | Lines in the current buffer |
|
||||||
| `:Tags [QUERY]` | Tags in the project (`ctags -R`) |
|
| `:Tags [QUERY]` | Tags in the project (`ctags -R`) |
|
||||||
| `:BTags [QUERY]` | Tags in the current buffer |
|
| `:BTags [QUERY]` | Tags in the current buffer |
|
||||||
| `:Marks` | Marks |
|
| `:Marks` | Marks |
|
||||||
| `:Windows` | Windows |
|
| `:Windows` | Windows |
|
||||||
| `:Locate PATTERN` | `locate` command output |
|
| `:Locate PATTERN` | `locate` command output |
|
||||||
| `:History` | `v:oldfiles` and open buffers |
|
| `:History` | `v:oldfiles` and open buffers |
|
||||||
| `:History:` | Command history |
|
| `:History:` | Command history |
|
||||||
| `:History/` | Search history |
|
| `:History/` | Search history |
|
||||||
| `:Snippets` | Snippets ([UltiSnips][us]) |
|
| `:Snippets` | Snippets ([UltiSnips][us]) |
|
||||||
| `:Commits` | Git commits (requires [fugitive.vim][f]) |
|
| `:Commits` | Git commits (requires [fugitive.vim][f]) |
|
||||||
| `:BCommits` | Git commits for the current buffer |
|
| `:BCommits` | Git commits for the current buffer; visual-select lines to track changes in the range |
|
||||||
| `:Commands` | Commands |
|
| `:Commands` | Commands |
|
||||||
| `:Maps` | Normal mode mappings |
|
| `:Maps` | Normal mode mappings |
|
||||||
| `:Helptags` | Help tags <sup id="a1">[1](#helptags)</sup> |
|
| `:Helptags` | Help tags <sup id="a1">[1](#helptags)</sup> |
|
||||||
| `:Filetypes` | File types
|
| `:Filetypes` | File types
|
||||||
|
|
||||||
- Most commands support `CTRL-T` / `CTRL-X` / `CTRL-V` key
|
- Most commands support `CTRL-T` / `CTRL-X` / `CTRL-V` key
|
||||||
|
|||||||
@@ -1201,7 +1201,7 @@ function! s:commits_sink(lines)
|
|||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:commits(buffer_local, args)
|
function! s:commits(range, buffer_local, args)
|
||||||
let s:git_root = s:get_git_root()
|
let s:git_root = s:get_git_root()
|
||||||
if empty(s:git_root)
|
if empty(s:git_root)
|
||||||
return s:warn('Not in git repository')
|
return s:warn('Not in git repository')
|
||||||
@@ -1215,16 +1215,19 @@ function! s:commits(buffer_local, args)
|
|||||||
let managed = !v:shell_error
|
let managed = !v:shell_error
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if a:buffer_local
|
if len(a:range) || a:buffer_local
|
||||||
if !managed
|
if !managed
|
||||||
return s:warn('The current buffer is not in the working tree')
|
return s:warn('The current buffer is not in the working tree')
|
||||||
endif
|
endif
|
||||||
let source .= ' --follow '.fzf#shellescape(current)
|
let source .= len(a:range)
|
||||||
|
\ ? printf(' -L %d,%d:%s --no-patch', a:range[0], a:range[1], fzf#shellescape(current))
|
||||||
|
\ : (' --follow '.fzf#shellescape(current))
|
||||||
|
let command = 'BCommits'
|
||||||
else
|
else
|
||||||
let source .= ' --graph'
|
let source .= ' --graph'
|
||||||
|
let command = 'Commits'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let command = a:buffer_local ? 'BCommits' : 'Commits'
|
|
||||||
let expect_keys = join(keys(get(g:, 'fzf_action', s:default_action)), ',')
|
let expect_keys = join(keys(get(g:, 'fzf_action', s:default_action)), ',')
|
||||||
let options = {
|
let options = {
|
||||||
\ 'source': source,
|
\ 'source': source,
|
||||||
@@ -1249,12 +1252,26 @@ function! s:commits(buffer_local, args)
|
|||||||
return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, a:args)
|
return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, a:args)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fzf#vim#commits(...)
|
" Heuristically determine if the user specified a range
|
||||||
return s:commits(0, a:000)
|
function! s:given_range(line1, line2)
|
||||||
|
" 1. From visual mode
|
||||||
|
" :'<,'>Commits
|
||||||
|
" 2. From command-line
|
||||||
|
" :10,20Commits
|
||||||
|
if a:line1 == line("'<") && a:line2 == line("'>") ||
|
||||||
|
\ (a:line1 != 1 || a:line2 != line('$'))
|
||||||
|
return [a:line1, a:line2]
|
||||||
|
endif
|
||||||
|
|
||||||
|
return []
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fzf#vim#buffer_commits(...)
|
function! fzf#vim#commits(...) range
|
||||||
return s:commits(1, a:000)
|
return s:commits(s:given_range(a:firstline, a:lastline), 0, a:000)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! fzf#vim#buffer_commits(...) range
|
||||||
|
return s:commits(s:given_range(a:firstline, a:lastline), 1, a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
fzf-vim.txt fzf-vim Last change: December 14 2020
|
fzf-vim.txt fzf-vim Last change: May 24 2021
|
||||||
FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc*
|
FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc*
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ COMMANDS *fzf-vim-commands*
|
|||||||
`:History/` | Search history
|
`:History/` | Search history
|
||||||
`:Snippets` | Snippets ({UltiSnips}{9})
|
`:Snippets` | Snippets ({UltiSnips}{9})
|
||||||
`:Commits` | Git commits (requires {fugitive.vim}{10})
|
`:Commits` | Git commits (requires {fugitive.vim}{10})
|
||||||
`:BCommits` | Git commits for the current buffer
|
`:BCommits` | Git commits for the current buffer; visual-select lines to track changes in the range
|
||||||
`:Commands` | Commands
|
`:Commands` | Commands
|
||||||
`:Maps` | Normal mode mappings
|
`:Maps` | Normal mode mappings
|
||||||
`:Helptags` | Help tags [1]
|
`:Helptags` | Help tags [1]
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ call s:defs([
|
|||||||
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
|
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
|
||||||
\'command! -bar -bang Helptags call fzf#vim#helptags(<bang>0)',
|
\'command! -bar -bang Helptags call fzf#vim#helptags(<bang>0)',
|
||||||
\'command! -bar -bang Windows call fzf#vim#windows(<bang>0)',
|
\'command! -bar -bang Windows call fzf#vim#windows(<bang>0)',
|
||||||
\'command! -bar -bang Commits call fzf#vim#commits(fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
|
\'command! -bar -bang -range=% Commits <line1>,<line2>call fzf#vim#commits(fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
|
||||||
\'command! -bar -bang BCommits call fzf#vim#buffer_commits(fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
|
\'command! -bar -bang -range=% BCommits <line1>,<line2>call fzf#vim#buffer_commits(fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
|
||||||
\'command! -bar -bang Maps call fzf#vim#maps("n", <bang>0)',
|
\'command! -bar -bang Maps call fzf#vim#maps("n", <bang>0)',
|
||||||
\'command! -bar -bang Filetypes call fzf#vim#filetypes(<bang>0)',
|
\'command! -bar -bang Filetypes call fzf#vim#filetypes(<bang>0)',
|
||||||
\'command! -bang -nargs=* History call s:history(<q-args>, fzf#vim#with_preview(), <bang>0)'])
|
\'command! -bang -nargs=* History call s:history(<q-args>, fzf#vim#with_preview(), <bang>0)'])
|
||||||
|
|||||||
Reference in New Issue
Block a user