Telescope extension which lets you open and preview the current file at any previous commit, without detaching HEAD (i.e., without using git checkout
). The file can be opened in the current buffer, new split, new tab or in your web browser. The file is opened as a fugitive-object
, so all vim-fugitive
mappings can be used.
:Telescope git_bcommits
?There are a few key differences between this plugin and :Telescope git_bcommits
:
git_bcommits
checks out the entire repository on selection, which affects everything you are currently doing. If you have unstaged changes the checkout will also fail.foo.lua
at a specific commit but is now called bar/baz.lua
, the preview will still be shown. This is not the case for git_bcommits
. The actions will also work as expected.git_bcommits
shows the diff.git
Add this plugin as a dependency to telescope.nvim
, like this:
{
"nvim-telescope/telescope.nvim",
dependencies = {
{
"isak102/telescope-git-file-history.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"tpope/vim-fugitive"
}
}
}
}
Call require("telescope").load_extension("git_file_history")
somewhere after your telescope setup:
require("telescope").setup({
-- Your telescope config here
})
require("telescope").load_extension("git_file_history")
Configure this plugin by using the extensions.git_file_history
table in your telescope configuration. This plugin comes with the following defaults:
local gfh_actions = require("telescope").extensions.git_file_history.actions
require("telescope").setup({
-- The rest of your telescope config here
extensions = {
git_file_history = {
-- Keymaps inside the picker
mappings = {
i = {
["<C-g>"] = gfh_actions.open_in_browser,
},
n = {
["<C-g>"] = gfh_actions.open_in_browser,
},
},
-- The command to use for opening the browser (nil or string)
-- If nil, it will check if xdg-open, open, start, wslview are available, in that order.
browser_command = nil,
},
},
})
Run :Telescope git_file_history
or use:
require("telescope").extensions.git_file_history.git_file_history()
This plugin does not define any keymaps for opening the actual picker, but it has some default keymaps inside the picker:
Keymaps | Action |
---|---|
<C-g> |
Open current file at commit in web browser |
select (Telescope default: <CR> ) |
Open current file at commit in current buffer |
select_vertical (Telescope default: <C-v> ) |
Open current file at commit in vertical split |
select_horizontal (Telescope default: <C-x> ) |
Open current file at commit in horizontal split |
select_tab (Telescope default: <C-t> ) |
Open current file at commit in new tab |
The select
, select_vertical
, select_horizontal
and select_tab
keymaps are configured by telescope.