Skip to content

Instantly share code, notes, and snippets.

@jwarby
Created September 17, 2015 06:35
Show Gist options
  • Save jwarby/54769b9dd4dca15ecda8 to your computer and use it in GitHub Desktop.
Save jwarby/54769b9dd4dca15ecda8 to your computer and use it in GitHub Desktop.
Append hashtags to the end of a commit message in Vim - intended for adding the initials of peer reviewers, but will work for any tags (you may want to change the function name if so). Usage: :PRed JB EC / :PRed JB / :PRed JB EC DS, etc
function! AddPeerReviewerInitials(...)
" Go to the top of the file
execute ':normal gg'
" Find the first comment line, and go up one line
let lineIndex = search('^#') - 1
" If line is blank, go up another one (my setup adds a new line when amending commit messages)
if !getline(lineIndex)
let lineIndex = lineIndex - 1
endif
let index = 1
" Loop through tags and append to end of line
while index <= a:0
execute lineIndex . ':normal A #' . a:{index}
let index = index + 1
endwhile
endfunction
command! -nargs=+ -complete=command PRed call AddPeerReviewerInitials(<f-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment