Created
September 9, 2013 09:49
-
-
Save actionshrimp/6493611 to your computer and use it in GitHub Desktop.
A vim-fugitive status window toggle (mapped to F3). Seems to work nicely
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! ToggleGStatus() | |
if buflisted(bufname('.git/index')) | |
bd .git/index | |
else | |
Gstatus | |
endif | |
endfunction | |
command ToggleGStatus :call ToggleGStatus() | |
nmap <F3> :ToggleGStatus<CR> |
@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 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you for this, been using a while but now seems like this commit has changed the bufname to something like:
i couldn't come up with a quick fix, as the bufname changes depending on path; any ideas?