Created
January 15, 2021 06:16
-
-
Save beenhere4hours/98b44089558241ba18c4522135b00363 to your computer and use it in GitHub Desktop.
This file contains 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
" git commit message config | |
autocmd FileType gitcommit set textwidth=72 | |
autocmd FileType gitcommit set colorcolumn=73 | |
" git populate commit template with variables | |
" https://vi.stackexchange.com/a/11900 | |
function! s:expand_commit_template() abort | |
let branch = split(matchstr(system('git rev-parse --abbrev-ref HEAD'), '\p\+'), "-") | |
let context = { | |
\ 'TICKET_SYSTEM': branch[0], | |
\ 'TICKET_NUMBER': branch[1], | |
\ } | |
let lnum = nextnonblank(1) | |
while lnum && lnum < line('$') | |
call setline(lnum, substitute(getline(lnum), '\${\(\w\+\)}', | |
\ '\=get(context, submatch(1), submatch(0))', 'g')) | |
let lnum = nextnonblank(lnum + 1) | |
endwhile | |
endfunction | |
autocmd BufRead */.git/COMMIT_EDITMSG call s:expand_commit_template() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment