Last active
August 10, 2023 12:57
-
-
Save doitian/4c849956f5c97bd1115351142d446853 to your computer and use it in GitHub Desktop.
Open history version files from Git in Vim via LazyGit
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
# yaml-language-server: $schema=https://json.schemastore.org/lazygit.json | |
promptToReturnFromSubprocess: false | |
os: | |
editPreset: "nvim" | |
customCommands: | |
- key: E | |
context: commitFiles | |
subprocess: true | |
# - When a file is selected, open the file before the commit | |
# - When a directory is selected, open the commit changes limited to that directory | |
command: | | |
{{if .SelectedCommitFile}} | |
git show '{{.SelectedLocalCommit.Sha}}^:{{.SelectedCommitFile.Name}}' |\ | |
vim -Rm - +"let b:fname = 'file git://{{.SelectedLocalCommit.Sha}}^/{{.SelectedCommitFile.Name}}'" \ | |
{{else}} | |
git show '{{.SelectedLocalCommit.Sha}}' -- git show {{.SelectedCommitFilePath}} |\ | |
vim -Rm - +"let b:fname = 'file git://{{.SelectedLocalCommit.Sha}}/{{.SelectedCommitFilePath}}.patch'" \ | |
{{end}}--cmd 'set mls=0' \ | |
+'nnoremap <buffer> q <Cmd>quit<CR>' \ | |
+"exec 'file '.fnameescape(b:fname) | unlet b:fname | set mls=5 | silent! filetype detect" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The gotchas to open stdin in vim/nvim
filetype detect
withsilent!
.fnameescape
to escape the file name since Vim tries to expand%
,#
and other symbols in cmdline.-M
does not work well with plugin like Telescope.