dblume commited on 2023-02-10 21:28:21
Showing 1 changed files, with 33 additions and 3 deletions.
... | ... |
@@ -140,9 +140,39 @@ function! OpenCurrentAsNewTab() |
140 | 140 |
endfunction |
141 | 141 |
nmap <leader>o :call OpenCurrentAsNewTab()<CR> |
142 | 142 |
|
143 |
-" git blame (uses # instead of % for file) |
|
144 |
-" Delete this line when you install https://github.com/tpope/vim-fugitive |
|
145 |
-command Blame tabnew | r! git blame # |
|
143 |
+" git blame, show, and diff |
|
144 |
+" Delete these functions when you install https://github.com/tpope/vim-fugitive |
|
145 |
+function! GitBlame() |
|
146 |
+ let l:fname = expand('%:t') |
|
147 |
+ exec 'tabnew | r! git blame ' . shellescape(expand('%')) |
|
148 |
+ setl buftype=nofile |
|
149 |
+ exec 'silent :file git blame ' . l:fname |
|
150 |
+endfunction |
|
151 |
+command Blame :call GitBlame() |
|
152 |
+ |
|
153 |
+function! GitShow() |
|
154 |
+ let l:hash = expand('<cword>') |
|
155 |
+ exec 'tabnew | r! git show ' . l:hash |
|
156 |
+ setl buftype=nofile |
|
157 |
+ 0d_ |
|
158 |
+ exec 'silent :file git show ' . l:hash |
|
159 |
+endfunction |
|
160 |
+command Show :call GitShow() |
|
161 |
+ |
|
162 |
+function! GitDiff() |
|
163 |
+ let l:fname = expand('%:t') |
|
164 |
+ let l:buf = winbufnr(0) |
|
165 |
+ exec ':tabnew | r! git show HEAD:$(git rev-parse --show-prefix)' . l:fname |
|
166 |
+ setl buftype=nofile |
|
167 |
+ 0d_ |
|
168 |
+ exec 'silent :file git show HEAD:' . l:fname |
|
169 |
+ exec 'vert sb '.l:buf |
|
170 |
+ windo diffthis |
|
171 |
+ setl buftype=nofile |
|
172 |
+ wincmd r |
|
173 |
+ wincmd l |
|
174 |
+endfunction |
|
175 |
+command Diff :call GitDiff() |
|
146 | 176 |
|
147 | 177 |
" pastetoggle |
148 | 178 |
nmap <leader>p :set invpaste paste?<cr> |
149 | 179 |