-
-
Save actionshrimp/6493611 to your computer and use it in GitHub Desktop.
function! ToggleGStatus() | |
if buflisted(bufname('.git/index')) | |
bd .git/index | |
else | |
Gstatus | |
endif | |
endfunction | |
command ToggleGStatus :call ToggleGStatus() | |
nmap <F3> :ToggleGStatus<CR> |
Awesome, thank you!
That's exactly what I was trying to add to my vimrc.
Many thanks !
thank you for this, been using a while but now seems like this commit has changed the bufname to something like:
fugitive:///path/to/dir/with/.git
i couldn't come up with a quick fix, as the bufname changes depending on path; any ideas?
@kenichi bufname
accepts a file pattern, you could use
bufname('fugitive:///*/.git/')
to match the fugitive Git
buffer
and then you can use
execute ":bdelete" bufname('fugitive:///*/.git/')
to delete the buffer
EDIT:
Fugitive adds a second /
at the end, use
bufname('fugitive:///*/.git//$')
For thos who wants this in lua for neovim
local function showFugitiveGit()
if vim.fn.FugitiveHead() ~= '' then
vim.cmd [[
Git
" wincmd H " Open Git window in vertical split
" setlocal winfixwidth
" vertical resize 31
" setlocal winfixwidth
setlocal nonumber
setlocal norelativenumber
]]
end
end
local function toggleFugitiveGit()
if vim.fn.buflisted(vim.fn.bufname('fugitive:///*/.git//$')) ~= 0 then
vim.cmd[[ execute ":bdelete" bufname('fugitive:///*/.git//$') ]]
else
showFugitiveGit()
end
end
vim.keymap.set('n', '<F3>', toggleFugitiveGit, opts)
EDIT: fixed typo
@Fymyte thank you very much!
side note - experimenting both with and without the '$'; while i appreciate that it mimics the original behavior closer with it, i actually kind of like it without.
@Fymyte Thanks for the lua snippet! (p.s. there is a typo, it should be if vim.fn.buflisted(vim.fn.bufname('fugitive:///*/.git//$')) ~= 0 then
)
@disselkamp thanks for the report 👍
Thanks! Worked like a charm.