Dotfiles/site-modules/core/files/vim/ftplugin/prr.vim
Ade Attwood 2d7ab84b3a feat(vim): add prr plugin for a better code review experience
Sets code folding of diffs and hunks so we can review hunks on there
own. This is good for larger pull requests, you can focus on the hunk
and not get overwhelmed by the rest of the code.

Adds a go to definition mapping for prr lines. This will allow you to go
straight to the line of code when reviewing a pull request. Seeing the
code in full context is really helpful when reviewing. You are then
there in your editor with all the linters and the LSP.
2023-10-15 15:40:41 +01:00

31 lines
881 B
VimL

"
" function for the `foldexpr` to fold git diffs and hunks
"
" Inspired from https://github.com/sgeb/vim-diff-fold
"
function! s:fold_diff_hunk()
let l:line=getline(v:lnum)
if l:line =~# '^> \(diff\|Index\)'
return '>1'
elseif l:line =~# '^> \(@@\|\d\)'
return '>2'
elseif l:line =~# '^> \*\*\* \d\+,\d\+ \*\*\*\*$'
return '>2'
elseif l:line =~# '^> --- \d\+,\d\+ ----$'
return '>2'
else
return '='
endif
endfunction
setlocal foldenable
setlocal nomodeline formatoptions-=croq formatoptions+=tl
setlocal foldmethod=expr
setlocal foldexpr=s:fold_diff_hunk()
setlocal foldlevel=99
" Add "go to definition" mapping for prr lines. This will allow you to go to
" the line of code when reviewing a pull request. Seeing the code in full
" context is really helpful when reviewing.
noremap <silent> gd :PrrGoToLine<cr>