tpope / vim-fugitive

fugitive.vim: A Git wrapper so awesome, it should be illegal
https://www.vim.org/scripts/script.php?script_id=2975
20.1k stars 1.01k forks source link

Allow to diff in a new tab on diffing in :Gstatus #1451

Closed lourenci closed 4 years ago

lourenci commented 4 years ago

First off, thanks for the plugin.

I'd like to perform a diff on the file under the cursor in :Gstatus without waste part of my screen with the :Gstatus window. Is there some way to perform this diff in a new tab? I just found these maps in the docs:

dd                      Perform a |:Gdiffsplit| on the file under the cursor.
dv                      Perform a |:Gvdiffsplit| on the file under the cursor.
ds|dh                Perform a |:Ghdiffsplit| on the file under the cursor.
koroliov commented 4 years ago

you definitely can open a new tab with the buffer you want to see diffs for and run :Gvdiffsplit. Also it must work, if you press dv and close the status window with either :q or gq, the diff window will remain, I did it just yesterday

lourenci commented 4 years ago

This is not practical. Most of the time, I want to diff more than one file, so closing :Gstatus will make me have to open it again. It's so simple with another tab, I could simply close the tab to be in :Gstatus again.

tpope commented 4 years ago

:Git difftool -y <file> opens a diff in a new tab. There's no map for it, but you could implement your own on top of the . map.

lourenci commented 4 years ago

Can I open a PR for that, @tpope? Thanks for the library.

tpope commented 4 years ago

I want to retool maps such that the big leader keys like d and c bring up an interactive popup window, and until that happens, I'm not really interested in continuing to pile onto the existing mess. I recommend implementing such a map locally using autcocmd User FugitiveIndex.

flipsi commented 3 years ago

Sorry for necrobumping, but I want to have create a mapping just like you suggested, @tpope, and fail to do so.

I want the mapping to open a diff against HEAD in a new tab for the file under cursor. There are two problems:

My draft:

augroup custom_fugitive_mappings
    au!
    au User FugitiveIndex nnoremap <buffer> dt :tab Gdiffsplit @ <filename>
augroup END

How can I do this with fugitive? Is there a fugitive-way to get <filename>? In the :help fugitive-revision I didn't find anything. I'd prefer to call some fugitive function for this, instead of hacking something with getline('.').

Any help would be appreciated.


Nevermind, I found this and tweaked it a little.

So for everyone else with this problem, I've got a working solution:

function! GStatusGetFilenameUnderCursor()
    return matchstr(getline('.'), '^[A-Z?] \zs.*')
endfunction

command! GdiffsplitTab call GdiffsplitTab(expand("%"))
function! GdiffsplitTab(filename)
    exe 'tabedit ' . a:filename
    Gdiffsplit
endfunction

" custom mapping in fugitive window (:Git)
augroup custom_fugitive_mappings
    au!
    au User FugitiveIndex nnoremap <buffer> dt :call GdiffsplitTab(GStatusGetFilenameUnderCursor())<cr>
augroup END
tpope commented 3 years ago

Fugitive index buffers remap <C-R><C-F> to do this, and there's an equivalent <Plug> map of <Plug><cfile>.

Andoku commented 3 years ago

@tpope @sflip So what's the best way to open diffs in tab from :Git? I didn't quite understand about , can you elaborate please? This feature will be really useful, because it is easier to examine diffs in full window.

tpope commented 3 years ago

Plugging into the original proposition it would look something like

au User FugitiveIndex nmap <buffer> dt :Gtabedit <Plug><cfile><Bar>Gdiffsplit<CR>
Andoku commented 3 years ago

@tpope Perfect, thanks a lot. Why not to add it into plugin? I think it's super useful.

andrescuco commented 3 years ago

Would love to see this put into fugitive, I think it makes a lot of sense.

PhilippFeO commented 10 months ago

Plugging into the original proposition it would look something like

au User FugitiveIndex nmap <buffer> dt :Gtabedit <Plug><cfile><Bar>Gdiffsplit<CR>

What is the benefit of using an Autocommand on FugitiveIndex over creating the mapping via ftplugin/fugitive.{vim,lua}?